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>
Jeff King committed
Aug 27, 2020 at 01:25 UTC
27ed6ccc12a331a1e6014f2fe101a2c551167e9e
1 file changed
+3
-5
builtin/worktree.c
+3
-5
@@ -924,7 +924,6 @@ static int move_worktree(int ac, const char **av, const char *prefix)
924
static void check_clean_worktree(struct worktree *wt,
925
const char *original_path)
926
{
927
- struct argv_array child_env = ARGV_ARRAY_INIT;
927
struct child_process cp;
928
char buf[1];
929
int ret;
@@ -935,15 +934,14 @@ static void check_clean_worktree(struct worktree *wt,
934
*/
935
validate_no_submodules(wt);
936
938
- argv_array_pushf(&child_env, "%s=%s/.git",
937
+ child_process_init(&cp);
938
+ argv_array_pushf(&cp.env_array, "%s=%s/.git",
939
GIT_DIR_ENVIRONMENT, wt->path);
940
- argv_array_pushf(&child_env, "%s=%s",
940
+ argv_array_pushf(&cp.env_array, "%s=%s",
941
GIT_WORK_TREE_ENVIRONMENT, wt->path);
942
- memset(&cp, 0, sizeof(cp));
942
argv_array_pushl(&cp.args, "status",
943
"--porcelain", "--ignore-submodules=none",
944
NULL);
946
- cp.env = child_env.argv;
945
cp.git_cmd = 1;
946
cp.dir = wt->path;
947
cp.out = -1;