]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tac: don't leak a file descriptor for each non-seekable input
authorJim Meyering <meyering@redhat.com>
Sun, 16 Oct 2011 10:14:05 +0000 (12:14 +0200)
committerJim Meyering <meyering@redhat.com>
Mon, 17 Oct 2011 15:44:54 +0000 (17:44 +0200)
* src/tac.c (tac_nonseekable): Call fclose and free tmp_file after
each successful call to copy_to_temp.

src/tac.c

index 2898199a25d7957d2bff080a870d530a0dcca9ef..97b19aec7da75dc10046b0382337a83de0e91dae 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -511,16 +511,13 @@ tac_nonseekable (int input_fd, const char *file)
 {
   FILE *tmp_stream;
   char *tmp_file;
-  if (copy_to_temp (&tmp_stream, &tmp_file, input_fd, file))
-    {
-      if (tac_seekable (fileno (tmp_stream), tmp_file))
-        {
-          free (tmp_file);
-          return true;
-        }
-    }
+  if (!copy_to_temp (&tmp_stream, &tmp_file, input_fd, file))
+    return false;
 
-  return false;
+  bool ok = tac_seekable (fileno (tmp_stream), tmp_file);
+  fclose (tmp_stream);
+  free (tmp_file);
+  return ok;
 }
 
 /* Print FILE in reverse, copying it to a temporary