From: Jim Meyering Date: Sun, 16 Oct 2011 10:14:05 +0000 (+0200) Subject: tac: don't leak a file descriptor for each non-seekable input X-Git-Tag: v8.15~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=866844826c3274d1ca8487aaa23dbc3b55c4fa59;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/src/tac.c b/src/tac.c index 2898199a25..97b19aec7d 100644 --- 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