Skip to content

Commit 623bd7d

Browse files
avargitster
authored andcommitted
submodule--helper: fix a leak in module_add()
Fix a leak in module_path(), since a6226fd (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10), we've been freeing add_data.sm_path, but in this case we clobbered it, and didn't free the value we clobbered. This makes test 28 of "t/t7400-submodule-basic.sh" ("submodule add in subdirectory") pass when we're compiled with SANITIZE=leak.. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Reviewed-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4e83605 commit 623bd7d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,8 +3314,12 @@ static int module_add(int argc, const char **argv, const char *prefix)
33143314
else
33153315
add_data.sm_path = xstrdup(argv[1]);
33163316

3317-
if (prefix && *prefix && !is_absolute_path(add_data.sm_path))
3318-
add_data.sm_path = xstrfmt("%s%s", prefix, add_data.sm_path);
3317+
if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) {
3318+
char *sm_path = add_data.sm_path;
3319+
3320+
add_data.sm_path = xstrfmt("%s%s", prefix, sm_path);
3321+
free(sm_path);
3322+
}
33193323

33203324
if (starts_with_dot_dot_slash(add_data.repo) ||
33213325
starts_with_dot_slash(add_data.repo)) {

0 commit comments

Comments
 (0)