Skip to content

Commit 0a4d315

Browse files
avargitster
authored andcommitted
submodule--helper: don't leak {run,capture}_command() cp.dir argument
Fix a memory leak in c51f8f9 (submodule--helper: run update procedures from C, 2021-08-24) and 3c3558f (submodule--helper: run update using child process struct, 2022-03-15) by not allocating memory in the first place. The "dir" member of "struct child_process" will not be modified by that API, and it's declared to be "const char *". So let's not needlessly duplicate these strings. 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 4b9d124 commit 0a4d315

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/submodule--helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ static int is_tip_reachable(const char *path, const struct object_id *oid)
21262126
char *hex = oid_to_hex(oid);
21272127

21282128
cp.git_cmd = 1;
2129-
cp.dir = xstrdup(path);
2129+
cp.dir = path;
21302130
cp.no_stderr = 1;
21312131
strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL);
21322132

@@ -2145,7 +2145,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
21452145

21462146
prepare_submodule_repo_env(&cp.env);
21472147
cp.git_cmd = 1;
2148-
cp.dir = xstrdup(module_path);
2148+
cp.dir = module_path;
21492149

21502150
strvec_push(&cp.args, "fetch");
21512151
if (quiet)
@@ -2198,7 +2198,7 @@ static int run_update_command(const struct update_data *ud, int subforce)
21982198
}
21992199
strvec_push(&cp.args, oid);
22002200

2201-
cp.dir = xstrdup(ud->sm_path);
2201+
cp.dir = ud->sm_path;
22022202
prepare_submodule_repo_env(&cp.env);
22032203
if ((ret = run_command(&cp))) {
22042204
switch (ud->update_strategy.type) {

0 commit comments

Comments
 (0)