Skip to content

Commit 8f79015

Browse files
avargitster
authored andcommitted
submodule--helper: fix trivial leak in module_add()
Fix a memory leak in code added in a6226fd (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10). If "realrepo" isn't a copy of the "repo" member we should free() it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f0d118 commit 8f79015

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

builtin/submodule--helper.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
33093309
{
33103310
int force = 0, quiet = 0, progress = 0, dissociate = 0;
33113311
struct add_data add_data = ADD_DATA_INIT;
3312+
char *to_free = NULL;
33123313

33133314
struct option options[] = {
33143315
OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
@@ -3360,7 +3361,8 @@ static int module_add(int argc, const char **argv, const char *prefix)
33603361
"of the working tree"));
33613362

33623363
/* dereference source url relative to parent's url */
3363-
add_data.realrepo = resolve_relative_url(add_data.repo, NULL, 1);
3364+
to_free = resolve_relative_url(add_data.repo, NULL, 1);
3365+
add_data.realrepo = to_free;
33643366
} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
33653367
add_data.realrepo = add_data.repo;
33663368
} else {
@@ -3413,6 +3415,7 @@ static int module_add(int argc, const char **argv, const char *prefix)
34133415
}
34143416
configure_added_submodule(&add_data);
34153417
free(add_data.sm_path);
3418+
free(to_free);
34163419

34173420
return 0;
34183421
}

0 commit comments

Comments
 (0)