git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] run-command: export child_process_clear()

From
René Scharfe <l.s.r@web.de>
Date
Oct 31, 2015, 09:20 UTC
Message-ID
<563487C6.4050504@web.de>
In-Reply-To
<56348709.9080207@web.de>

Make the API symmetric by including a cleanup function as a counterpart to child_process_init().

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 Documentation/technical/api-run-command.txt | 7 +++++++
 run-command.c                               | 2 +-
 run-command.h                               | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/Documentation/technical/api-run-command.txt b/Documentation/technical/api-run-command.txt
index a9fdb45..8bf3e37 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 b10ec75..0a3c24e 100644
--- a/run-command.c
+++ b/run-command.c
@@ -13,7 +13,7 @@ void child_process_init(struct child_process *child)
 	argv_array_init(&child->env_array);
 }
 
-static void child_process_clear(struct child_process *child)
+void child_process_clear(struct child_process *child)
 {
 	argv_array_clear(&child->args);
 	argv_array_clear(&child->env_array);
diff --git a/run-command.h b/run-command.h
index 9fe37ee..e296bd2 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 *);
-- 
2.6.2
Previous: René ScharfeNext: René Scharfe
Message 3 of 6 in “daemon: plug memory leak”
  1. 0/3 daemon: plug memory leakRené Scharfe, Oct 31, 2015
  2. 1/3 run-command: name the cleanup function child_process_clear()René Scharfe, Oct 31, 2015
  3. 2/3 run-command: export child_process_clear()René Scharfe, Oct 31, 2015
  4. 3/3 daemon: plug memory leakRené Scharfe, Oct 31, 2015
  5. Jeff KingOct 31, 2015
  6. Stefan BellerOct 31, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.