aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-03-22 06:35:02 -0400
committerJunio C Hamano <gitster@pobox.com>2024-03-22 10:21:35 -0700
commit647e870a08e31984f5f42703f3618ff378a72932 (patch)
tree4b3218c58d1d789c999ca2c9eba63a718402c99a /builtin
parent0d1bd1dfb37ef25e1911777c94129fc769ffec38 (diff)
downloadgit-647e870a08e31984f5f42703f3618ff378a72932.tar.gz
rebase: use child_process_clear() to clean
In the run_am() function, we set up a child_process struct to run "git-am", allocating memory for its args and env strvecs. These are normally cleaned up when we call run_command(). But if we encounter certain errors, we exit the function early and try to clean up ourselves by clearing the am.args field. This leaks the "env" strvec. We should use child_process_clear() instead, which covers both. And more importantly, it future proofs us against the struct ever growing more allocated fields. These are unlikely errors to happen in practice, so they don't actually trigger the leak sanitizer in the tests. But we can add a new test which does exercise one of the paths (and fails SANITIZE=leak without this patch). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/rebase.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 6635f10d52..acd083bec3 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -653,7 +653,7 @@ static int run_am(struct rebase_options *opts)
status = error_errno(_("could not open '%s' for writing"),
rebased_patches);
free(rebased_patches);
- strvec_clear(&am.args);
+ child_process_clear(&am);
return status;
}
@@ -676,7 +676,7 @@ static int run_am(struct rebase_options *opts)
struct reset_head_opts ropts = { 0 };
unlink(rebased_patches);
free(rebased_patches);
- strvec_clear(&am.args);
+ child_process_clear(&am);
ropts.oid = &opts->orig_head->object.oid;
ropts.branch = opts->head_name;
@@ -699,7 +699,7 @@ static int run_am(struct rebase_options *opts)
status = error_errno(_("could not open '%s' for reading"),
rebased_patches);
free(rebased_patches);
- strvec_clear(&am.args);
+ child_process_clear(&am);
return status;
}