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:
-rw-r--r--Documentation/technical/api-run-command.txt7
-rw-r--r--run-command.c15
-rw-r--r--run-command.h1
3 files changed, 17 insertions, 6 deletions
diff --git a/Documentation/technical/api-run-command.txt b/Documentation/technical/api-run-command.txt
index a9fdb45b93..8bf3e37f53 100644
--- a/Documentation/technical/api-run-command.txt
+++ b/Documentation/technical/api-run-command.txt
@@ -46,6 +46,13 @@ Functions
The argument dir corresponds the member .dir. The argument env
corresponds to the member .env.
+`child_process_clear`::
+
+ Release the memory associated with the struct child_process.
+ Most users of the run-command API don't need to call this
+ function explicitly because `start_command` invokes it on
+ failure and `finish_command` calls it automatically already.
+
The functions above do the following:
. If a system call failed, errno is set and -1 is returned. A diagnostic
diff --git a/run-command.c b/run-command.c
index aad03ab705..fc391fb9cd 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;
@@ -336,8 +342,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;
}
@@ -523,8 +528,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;
}
@@ -550,8 +554,7 @@ fail_pipe:
int finish_command(struct child_process *cmd)
{
int ret = wait_or_whine(cmd->pid, cmd->argv[0]);
- argv_array_clear(&cmd->args);
- argv_array_clear(&cmd->env_array);
+ child_process_clear(cmd);
return ret;
}
diff --git a/run-command.h b/run-command.h
index 263b9662ad..c850a57ea6 100644
--- a/run-command.h
+++ b/run-command.h
@@ -47,6 +47,7 @@ struct child_process {
#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT, ARGV_ARRAY_INIT }
void child_process_init(struct child_process *);
+void child_process_clear(struct child_process *);
int start_command(struct child_process *);
int finish_command(struct child_process *);