Skip to content

Commit 8efa2ac

Browse files
rscharfegitster
authored andcommitted
bisect--helper: release strbuf and strvec on run error
Move the cleanup code out of the loop and make sure all execution paths pass through it to avoid leaking memory. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80c2e96 commit 8efa2ac

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

builtin/bisect--helper.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11161116
if (res < 0 || 128 <= res) {
11171117
error(_("bisect run failed: exit code %d from"
11181118
" '%s' is < 0 or >= 128"), res, command.buf);
1119-
strbuf_release(&command);
1120-
return res;
1119+
break;
11211120
}
11221121

11231122
if (res == 125)
@@ -1129,8 +1128,10 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11291128

11301129
temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
11311130

1132-
if (temporary_stdout_fd < 0)
1133-
return error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run());
1131+
if (temporary_stdout_fd < 0) {
1132+
res = error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run());
1133+
break;
1134+
}
11341135

11351136
fflush(stdout);
11361137
saved_stdout = dup(1);
@@ -1159,11 +1160,12 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11591160
} else {
11601161
continue;
11611162
}
1162-
1163-
strbuf_release(&command);
1164-
strvec_clear(&run_args);
1165-
return res;
1163+
break;
11661164
}
1165+
1166+
strbuf_release(&command);
1167+
strvec_clear(&run_args);
1168+
return res;
11671169
}
11681170

11691171
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)