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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 18, 2022 at 13:46 UTC
8efa2acc2ed667eb7d80a533ace59f4722088c8b
1 file changed
+10
-8
builtin/bisect--helper.c
+10
-8
@@ -1116,8 +1116,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1116
if (res < 0 || 128 <= res) {
1117
error(_("bisect run failed: exit code %d from"
1118
" '%s' is < 0 or >= 128"), res, command.buf);
1119
- strbuf_release(&command);
1120
- return res;
1119
+ break;
1120
}
1121
1122
if (res == 125)
@@ -1129,8 +1128,10 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1128
1129
temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
1130
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
+ }
1135
1136
fflush(stdout);
1137
saved_stdout = dup(1);
@@ -1159,11 +1160,12 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1160
} else {
1161
continue;
1162
}
1162
-
1163
- strbuf_release(&command);
1164
- strvec_clear(&run_args);
1165
- return res;
1163
+ break;
1164
}
1165
+
1166
+ strbuf_release(&command);
1167
+ strvec_clear(&run_args);
1168
+ return res;
1169
}
1170
1171
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)