From d0986ff1042eab5b76da949b69bbd609f852c911 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <and@gmx.li>
Date: Tue, 8 Dec 2020 19:04:15 +0000
Subject: [PATCH] (utilunix.c) 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>
---
lib/utilunix.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/utilunix.c b/lib/utilunix.c
index bbcf86b78..8488afd63 100644
a
|
b
|
tilde_expand (const char *directory) |
715 | 715 | void |
716 | 716 | open_error_pipe (void) |
717 | 717 | { |
| 718 | int error_fd = -1; |
| 719 | |
718 | 720 | if (pipe (error_pipe) < 0) |
719 | 721 | message (D_NORMAL, _("Warning"), _("Pipe failed")); |
720 | 722 | |
721 | 723 | old_error = dup (STDERR_FILENO); |
722 | | if (old_error < 0 || close (STDERR_FILENO) != 0 || dup (error_pipe[1]) != STDERR_FILENO) |
| 724 | if (old_error < 0 || close (STDERR_FILENO) != 0 || (error_fd = dup (error_pipe[1])) != STDERR_FILENO) |
723 | 725 | { |
724 | 726 | message (D_NORMAL, _("Warning"), _("Dup failed")); |
725 | 727 | |
… |
… |
open_error_pipe (void) |
749 | 751 | } |
750 | 752 | } |
751 | 753 | } |
| 754 | if (error_fd >= 0) |
| 755 | close (error_fd); |
752 | 756 | /* we never write there */ |
753 | 757 | close (error_pipe[1]); |
754 | 758 | error_pipe[1] = -1; |