diff options
author | Jim Meyering <meyering@redhat.com> | 2011-10-16 12:14:05 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-10-17 17:44:54 +0200 |
commit | 866844826c3274d1ca8487aaa23dbc3b55c4fa59 (patch) | |
tree | 4afcc86c6f2370fbf40d718efa590743eaa2d88f | |
parent | 537f9da37fa396af72d8b3e6af274e0bcbeab794 (diff) | |
download | coreutils-866844826c3274d1ca8487aaa23dbc3b55c4fa59.tar.xz |
tac: don't leak a file descriptor for each non-seekable input
* src/tac.c (tac_nonseekable): Call fclose and free tmp_file after
each successful call to copy_to_temp.
-rw-r--r-- | src/tac.c | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -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 |