Skip to content

Commit 435285b

Browse files
avarttaylorr
authored andcommitted
submodule--helper: fix a memory leak in "status"
The "status" sub-command was leaking the "struct strvec" it was setting up for the reasons explained in f92dbdb (revisions API: don't leak memory on argv elements that need free()-ing, 2022-08-02), so let's use the "free_removed_argv_elements" option to setup_revisions() to fix the leak. Even if we did that, clobbering the "diff_files_args.nr" with the return value of setup_revisions() would leave leaks in place, but we can just stop clobbering it. Ever since that code was added in a9f8a37 (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06) we've had no reason to modify the "nr" member ("argc" at the time): The next use of "diff_files_args" after this is the "strvec_clear()" at the end of the function. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 44874cb commit 435285b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

builtin/submodule--helper.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
616616
int diff_files_result;
617617
struct strbuf buf = STRBUF_INIT;
618618
const char *git_dir;
619+
struct setup_revision_opt opt = {
620+
.free_removed_argv_elements = 1,
621+
};
619622

620623
if (!submodule_from_path(the_repository, null_oid(), path))
621624
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -649,9 +652,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
649652

650653
repo_init_revisions(the_repository, &rev, NULL);
651654
rev.abbrev = 0;
652-
diff_files_args.nr = setup_revisions(diff_files_args.nr,
653-
diff_files_args.v,
654-
&rev, NULL);
655+
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
655656
diff_files_result = run_diff_files(&rev, 0);
656657

657658
if (!diff_result_code(&rev.diffopt, diff_files_result)) {

t/t7422-submodule-output.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='submodule --cached, --quiet etc. output'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67
. "$TEST_DIRECTORY"/lib-t3100.sh
78

0 commit comments

Comments
 (0)