]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: "struct pathspec" memory leak in module_update()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 31 Aug 2022 23:14:11 +0000 (01:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Sep 2022 16:18:12 +0000 (09:18 -0700)
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>
builtin/submodule--helper.c

index 4bba1c7561044b043494aba19bffc43b234665b9..ef56471a8cf0a5f05974ed091d113c3831bade0e 100644 (file)
@@ -2561,6 +2561,7 @@ cleanup:
 static int module_update(int argc, const char **argv, const char *prefix)
 {
        struct pathspec pathspec = { 0 };
+       struct pathspec pathspec2 = { 0 };
        struct update_data opt = UPDATE_DATA_INIT;
        struct list_objects_filter_options filter_options = { 0 };
        int ret;
@@ -2649,7 +2650,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
                struct init_cb info = INIT_CB_INIT;
 
                if (module_list_compute(argc, argv, opt.prefix,
-                                       &pathspec, &list) < 0) {
+                                       &pathspec2, &list) < 0) {
                        ret = 1;
                        goto cleanup;
                }
@@ -2672,6 +2673,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
 cleanup:
        list_objects_filter_release(&filter_options);
        clear_pathspec(&pathspec);
+       clear_pathspec(&pathspec2);
        return ret;
 }