Thread (60 messages) flat view 60 messages, 5 authors, 26d ago

Re: [PATCH v2 11/11] bisect: handle dup() failure when redirecting stdout

From: Junio C Hamano <hidden>
Date: 2026-08-06 17:31:42

Jeff King [off-list ref] writes:
On Wed, Aug 05, 2026 at 06:31:00PM +0000, Johannes Schindelin via GitGitGadget wrote:
quoted
diff --git a/builtin/bisect.c b/builtin/bisect.c
index ceb60b0626..733d28d377 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1308,7 +1308,12 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
 
 		fflush(stdout);
 		saved_stdout = dup(1);
-		dup2(temporary_stdout_fd, 1);
+		if (saved_stdout < 0 ||
+		    dup2(temporary_stdout_fd, 1) < 0) {
+			res = error_errno(_("could not duplicate stdout"));
+			close(temporary_stdout_fd);
+			break;
+		}
Ironically this produces a new Coverity complaint. ;)

If dup2() fails, then we break out of the loop, leaking saved_stdout.
I didn't notice it while I was looking at this part, and wondering
if we can (and should) do anything if close() failed there.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help