(open_error_pipe): fix resource leak.

Save file handle for later close, if valid.

Found by Coverity.

Coverity id #32607.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andreas Mohr 2020-12-08 19:04:15 +00:00 committed by Andrew Borodin
parent 35911c08e1
commit 61f997de26
1 changed files with 6 additions and 1 deletions

View File

@ -715,11 +715,14 @@ tilde_expand (const char *directory)
void
open_error_pipe (void)
{
int error_fd = -1;
if (pipe (error_pipe) < 0)
message (D_NORMAL, _("Warning"), _("Pipe failed"));
old_error = dup (STDERR_FILENO);
if (old_error < 0 || close (STDERR_FILENO) != 0 || dup (error_pipe[1]) != STDERR_FILENO)
if (old_error < 0 || close (STDERR_FILENO) != 0
|| (error_fd = dup (error_pipe[1])) != STDERR_FILENO)
{
message (D_NORMAL, _("Warning"), _("Dup failed"));
@ -749,6 +752,8 @@ open_error_pipe (void)
}
}
}
if (error_fd >= 0)
close (error_fd);
/* we never write there */
close (error_pipe[1]);
error_pipe[1] = -1;