]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/submodule--helper: clear child process when not running it
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:46:11 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:34 +0000 (08:25 -0700)
In `runcommand_in_submodule_cb()` we may end up not executing the child
command when `argv` is empty. But we still populate the command with
environment variables and other things, which needs cleanup. This leads
to a memory leak because we do not call `finish_command()`.

Fix this by clearing the child process when we don't execute it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/t7407-submodule-foreach.sh

index ed05dc51347b7f5eac4eba46bb6b7f8b83eb91da..fd1b67940839f122b1500cb2a3030cf4bfb22e78 100644 (file)
@@ -363,9 +363,13 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
        if (!info->quiet)
                printf(_("Entering '%s'\n"), displaypath);
 
-       if (info->argv[0] && run_command(&cp))
-               die(_("run_command returned non-zero status for %s\n."),
-                       displaypath);
+       if (info->argv[0]) {
+               if (run_command(&cp))
+                       die(_("run_command returned non-zero status for %s\n."),
+                           displaypath);
+       } else {
+               child_process_clear(&cp);
+       }
 
        if (info->recursive) {
                struct child_process cpr = CHILD_PROCESS_INIT;
index 8d7b234beb8b09b2f6dbe459aad56315612925b8..9f688932613598bc558e1dddf0401217c985134b 100755 (executable)
@@ -12,6 +12,7 @@ that are currently checked out.
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh