Skip to content

Commit 8f786a8

Browse files
pks-tgitster
authored andcommitted
builtin/submodule--helper: clear child process when not running it
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e492f2 commit 8f786a8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

builtin/submodule--helper.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,13 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
363363
if (!info->quiet)
364364
printf(_("Entering '%s'\n"), displaypath);
365365

366-
if (info->argv[0] && run_command(&cp))
367-
die(_("run_command returned non-zero status for %s\n."),
368-
displaypath);
366+
if (info->argv[0]) {
367+
if (run_command(&cp))
368+
die(_("run_command returned non-zero status for %s\n."),
369+
displaypath);
370+
} else {
371+
child_process_clear(&cp);
372+
}
369373

370374
if (info->recursive) {
371375
struct child_process cpr = CHILD_PROCESS_INIT;

t/t7407-submodule-foreach.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ that are currently checked out.
1212
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1313
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1414

15+
TEST_PASSES_SANITIZE_LEAK=true
1516
. ./test-lib.sh
1617

1718

0 commit comments

Comments
 (0)