mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
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.
This commit is contained in:
1 parent
537f9da37f
commit
866844826c
1 file changed
+6
-9
@@ -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
|
||||
|
||||
Reference in new issue
Block a user