Skip to content

Commit 6771e20

Browse files
pks-tgitster
authored andcommitted
builtin/submodule--helper: fix leaking buffer in is_tip_reachable
The `rev` buffer in `is_tip_reachable()` is being populated with the output of git-rev-list(1) -- if either the command fails or the buffer contains any data, then the input commit is not reachable. The buffer isn't used for anything else, but neither do we free it, causing a memory leak. Fix this. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5535b3f commit 6771e20

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

builtin/submodule--helper.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,7 @@ static int is_tip_reachable(const char *path, const struct object_id *oid)
22682268
struct child_process cp = CHILD_PROCESS_INIT;
22692269
struct strbuf rev = STRBUF_INIT;
22702270
char *hex = oid_to_hex(oid);
2271+
int reachable;
22712272

22722273
cp.git_cmd = 1;
22732274
cp.dir = path;
@@ -2277,9 +2278,12 @@ static int is_tip_reachable(const char *path, const struct object_id *oid)
22772278
prepare_submodule_repo_env(&cp.env);
22782279

22792280
if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len)
2280-
return 0;
2281+
reachable = 0;
2282+
else
2283+
reachable = 1;
22812284

2282-
return 1;
2285+
strbuf_release(&rev);
2286+
return reachable;
22832287
}
22842288

22852289
static int fetch_in_submodule(const char *module_path, int depth, int quiet,
@@ -3222,6 +3226,7 @@ static int add_submodule(const struct add_data *add_data)
32223226
die(_("unable to checkout submodule '%s'"), add_data->sm_path);
32233227
}
32243228
ret = 0;
3229+
32253230
cleanup:
32263231
string_list_clear(&reference, 1);
32273232
return ret;

t/t7400-submodule-basic.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ subcommands of git submodule.
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
test_expect_success 'setup - enable local submodules' '

0 commit comments

Comments
 (0)