Skip to content

Commit 27ed6cc

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47ae905 commit 27ed6cc

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

builtin/worktree.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,6 @@ static int move_worktree(int ac, const char **av, const char *prefix)
924924
static void check_clean_worktree(struct worktree *wt,
925925
const char *original_path)
926926
{
927-
struct argv_array child_env = ARGV_ARRAY_INIT;
928927
struct child_process cp;
929928
char buf[1];
930929
int ret;
@@ -935,15 +934,14 @@ static void check_clean_worktree(struct worktree *wt,
935934
*/
936935
validate_no_submodules(wt);
937936

938-
argv_array_pushf(&child_env, "%s=%s/.git",
937+
child_process_init(&cp);
938+
argv_array_pushf(&cp.env_array, "%s=%s/.git",
939939
GIT_DIR_ENVIRONMENT, wt->path);
940-
argv_array_pushf(&child_env, "%s=%s",
940+
argv_array_pushf(&cp.env_array, "%s=%s",
941941
GIT_WORK_TREE_ENVIRONMENT, wt->path);
942-
memset(&cp, 0, sizeof(cp));
943942
argv_array_pushl(&cp.args, "status",
944943
"--porcelain", "--ignore-submodules=none",
945944
NULL);
946-
cp.env = child_env.argv;
947945
cp.git_cmd = 1;
948946
cp.dir = wt->path;
949947
cp.out = -1;

0 commit comments

Comments
 (0)