Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-08-27 08:25:04 +0300
committerJunio C Hamano <gitster@pobox.com>2020-08-27 18:30:17 +0300
commit27ed6ccc12a331a1e6014f2fe101a2c551167e9e (patch)
tree6542ae3eb9f193a729b512cf24f04303c2da7fb9 /builtin/worktree.c
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc (diff)
worktree: fix leak in check_clean_worktree()
We allocate a child_env strvec but never free its memory. Instead, let's just use the strvec that our child_process struct provides, which is cleaned up automatically when we run the command. And while we're moving the initialization of the child_process around, let's switch it to use the official init function (zero-initializing it works OK, since strvec is happy enough with that, but it sets a bad example). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f0cbdef718..8bfb79f3a5 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -924,7 +924,6 @@ static int move_worktree(int ac, const char **av, const char *prefix)
static void check_clean_worktree(struct worktree *wt,
const char *original_path)
{
- struct argv_array child_env = ARGV_ARRAY_INIT;
struct child_process cp;
char buf[1];
int ret;
@@ -935,15 +934,14 @@ static void check_clean_worktree(struct worktree *wt,
*/
validate_no_submodules(wt);
- argv_array_pushf(&child_env, "%s=%s/.git",
+ child_process_init(&cp);
+ argv_array_pushf(&cp.env_array, "%s=%s/.git",
GIT_DIR_ENVIRONMENT, wt->path);
- argv_array_pushf(&child_env, "%s=%s",
+ argv_array_pushf(&cp.env_array, "%s=%s",
GIT_WORK_TREE_ENVIRONMENT, wt->path);
- memset(&cp, 0, sizeof(cp));
argv_array_pushl(&cp.args, "status",
"--porcelain", "--ignore-submodules=none",
NULL);
- cp.env = child_env.argv;
cp.git_cmd = 1;
cp.dir = wt->path;
cp.out = -1;