summaryrefslogtreecommitdiffstats
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-08-02 17:33:16 +0200
committerJunio C Hamano <gitster@pobox.com>2022-08-03 20:12:36 +0200
commitf92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6 (patch)
tree3979a3f381b683906af43e422fefd5523dd88257 /builtin/submodule--helper.c
parentbisect.c: partially fix bisect_rev_setup() memory leak (diff)
downloadgit-f92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6.tar.xz
git-f92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6.zip
revisions API: don't leak memory on argv elements that need free()-ing
Add a "free_removed_argv_elements" member to "struct setup_revision_opt", and use it to fix several memory leaks. We have various memory leaks in APIs that take and munge "const char **argv", e.g. parse_options(). Sometimes these APIs are given the "argv" we get to the "main" function, in which case we don't leak memory, but other times we're giving it the "v" member of a "struct strvec" we created. There's several potential ways to fix those sort of leaks, we could add a "nodup" mode to "struct strvec", which would work for the cases where we push constant strings to it. But that wouldn't work as soon as we used strvec_pushf(), or otherwise needed to duplicate or create a string for that "struct strvec". Let's instead make it the responsibility of the revisions API. If it's going to clobber elements of argv it can also free() them, which it will now do if instructed to do so via "free_removed_argv_elements". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index fac52ade5e..b63f420ece 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1104,6 +1104,9 @@ static int compute_summary_module_list(struct object_id *head_oid,
{
struct strvec diff_args = STRVEC_INIT;
struct rev_info rev;
+ struct setup_revision_opt opt = {
+ .free_removed_argv_elements = 1,
+ };
struct module_cb_list list = MODULE_CB_LIST_INIT;
int ret = 0;
@@ -1121,7 +1124,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
init_revisions(&rev, info->prefix);
rev.abbrev = 0;
precompose_argv_prefix(diff_args.nr, diff_args.v, NULL);
- setup_revisions(diff_args.nr, diff_args.v, &rev, NULL);
+ setup_revisions(diff_args.nr, diff_args.v, &rev, &opt);
rev.diffopt.output_format = DIFF_FORMAT_NO_OUTPUT | DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = submodule_summary_callback;
rev.diffopt.format_callback_data = &list;