summaryrefslogtreecommitdiff
path: root/run-command.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-11-03 15:13:11 -0800
committerJunio C Hamano <gitster@pobox.com>2015-11-03 15:13:12 -0800
commitc3c592ef95ee21833e2214fb9068889dcac220c9 (patch)
tree6772b21ff5964ab2227d5c7acb4246eaa9729152 /run-command.c
parent6784eb5ad93da15d24a5d111a3d6df618f98532f (diff)
parentb1b49ff8d42a21ade6a72b40a147fd3eaff3db8d (diff)
downloadgit-c3c592ef95ee21833e2214fb9068889dcac220c9.tar.gz
Merge branch 'rs/daemon-plug-child-leak'
"git daemon" uses "run_command()" without "finish_command()", so it needs to release resources itself, which it forgot to do. * rs/daemon-plug-child-leak: daemon: plug memory leak run-command: factor out child_process_clear()
Diffstat (limited to 'run-command.c')
-rw-r--r--run-command.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/run-command.c b/run-command.c
index e17e456cda..13fa452e8c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -11,6 +11,12 @@ void child_process_init(struct child_process *child)
argv_array_init(&child->env_array);
}
+void child_process_clear(struct child_process *child)
+{
+ argv_array_clear(&child->args);
+ argv_array_clear(&child->env_array);
+}
+
struct child_to_clean {
pid_t pid;
struct child_to_clean *next;
@@ -327,8 +333,7 @@ int start_command(struct child_process *cmd)
fail_pipe:
error("cannot create %s pipe for %s: %s",
str, cmd->argv[0], strerror(failed_errno));
- argv_array_clear(&cmd->args);
- argv_array_clear(&cmd->env_array);
+ child_process_clear(cmd);
errno = failed_errno;
return -1;
}
@@ -513,8 +518,7 @@ fail_pipe:
close_pair(fderr);
else if (cmd->err)
close(cmd->err);
- argv_array_clear(&cmd->args);
- argv_array_clear(&cmd->env_array);
+ child_process_clear(cmd);
errno = failed_errno;
return -1;
}
@@ -540,8 +544,7 @@ fail_pipe:
int finish_command(struct child_process *cmd)
{
int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
- argv_array_clear(&cmd->args);
- argv_array_clear(&cmd->env_array);
+ child_process_clear(cmd);
return ret;
}