submodule--helper: "struct pathspec" memory leak in module_update()

The module_update() function calls module_list_compute() twice, which in turn will reset the "struct pathspec" passed to it. Let's instead track two of them, and clear them both. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:14 UTC 4b9d12460d18d02bf6f12cc3c96340e53acf03e3
1 file changed +3 -1
builtin/submodule--helper.c
+3 -1
@@ -2561,6 +2561,7 @@ cleanup:
2561 static int module_update(int argc, const char **argv, const char *prefix)
2562 {
2563 struct pathspec pathspec = { 0 };
2564 + struct pathspec pathspec2 = { 0 };
2565 struct update_data opt = UPDATE_DATA_INIT;
2566 struct list_objects_filter_options filter_options = { 0 };
2567 int ret;
@@ -2649,7 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2650 struct init_cb info = INIT_CB_INIT;
2651
2652 if (module_list_compute(argc, argv, opt.prefix,
2652 - &pathspec, &list) < 0) {
2653 + &pathspec2, &list) < 0) {
2654 ret = 1;
2655 goto cleanup;
2656 }
@@ -2672,6 +2673,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
2673 cleanup:
2674 list_objects_filter_release(&filter_options);
2675 clear_pathspec(&pathspec);
2676 + clear_pathspec(&pathspec2);
2677 return ret;
2678 }
2679