summaryrefslogtreecommitdiff
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-08-31 23:14:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-09-02 16:18:12 (GMT)
commit0a4d31537d66bd2249adc8d923e2e6829204059e (patch)
tree8b1bd2812a9dc69c193679c3495e0a52cea6b67a /builtin/submodule--helper.c
parent4b9d12460d18d02bf6f12cc3c96340e53acf03e3 (diff)
downloadgit-0a4d31537d66bd2249adc8d923e2e6829204059e.zip
git-0a4d31537d66bd2249adc8d923e2e6829204059e.tar.gz
git-0a4d31537d66bd2249adc8d923e2e6829204059e.tar.bz2
submodule--helper: don't leak {run,capture}_command() cp.dir argument
Fix a memory leak in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24) and 3c3558f0953 (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 <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ef56471..ebd00f5 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2126,7 +2126,7 @@ static int is_tip_reachable(const char *path, const struct object_id *oid)
char *hex = oid_to_hex(oid);
cp.git_cmd = 1;
- cp.dir = xstrdup(path);
+ cp.dir = path;
cp.no_stderr = 1;
strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL);
@@ -2145,7 +2145,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
prepare_submodule_repo_env(&cp.env);
cp.git_cmd = 1;
- cp.dir = xstrdup(module_path);
+ cp.dir = module_path;
strvec_push(&cp.args, "fetch");
if (quiet)
@@ -2198,7 +2198,7 @@ static int run_update_command(const struct update_data *ud, int subforce)
}
strvec_push(&cp.args, oid);
- cp.dir = xstrdup(ud->sm_path);
+ cp.dir = ud->sm_path;
prepare_submodule_repo_env(&cp.env);
if ((ret = run_command(&cp))) {
switch (ud->update_strategy.type) {