* [PATCH v2 1/3] run-command: name the cleanup function child_process_clear()
2015-10-31 9:16 [PATCH v2 0/3] daemon: plug memory leak René Scharfe
@ 2015-10-31 9:19 ` René Scharfe
2015-10-31 9:20 ` [PATCH v2 2/3] run-command: export child_process_clear() René Scharfe
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: René Scharfe @ 2015-10-31 9:19 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano, Jeff King, Stefan Beller
Rename child_process_deinit() to child_process_clear() in order to stay
consistent with similar cleanup functions like argv_array_clear(),
string_list_clear() etc.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
run-command.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/run-command.c b/run-command.c
index 82cc238..b10ec75 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_deinit(struct child_process *child)
+static void child_process_clear(struct child_process *child)
{
argv_array_clear(&child->args);
argv_array_clear(&child->env_array);
@@ -335,7 +335,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));
- child_process_deinit(cmd);
+ child_process_clear(cmd);
errno = failed_errno;
return -1;
}
@@ -520,7 +520,7 @@ fail_pipe:
close_pair(fderr);
else if (cmd->err)
close(cmd->err);
- child_process_deinit(cmd);
+ child_process_clear(cmd);
errno = failed_errno;
return -1;
}
@@ -546,7 +546,7 @@ fail_pipe:
int finish_command(struct child_process *cmd)
{
int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
- child_process_deinit(cmd);
+ child_process_clear(cmd);
return ret;
}
@@ -990,7 +990,7 @@ static void pp_cleanup(struct parallel_processes *pp)
for (i = 0; i < pp->max_processes; i++) {
strbuf_release(&pp->children[i].err);
- child_process_deinit(&pp->children[i].process);
+ child_process_clear(&pp->children[i].process);
}
free(pp->children);
@@ -1157,7 +1157,7 @@ static int pp_collect_finished(struct parallel_processes *pp)
pp->nr_processes--;
pp->children[i].in_use = 0;
pp->pfd[i].fd = -1;
- child_process_deinit(&pp->children[i].process);
+ child_process_clear(&pp->children[i].process);
child_process_init(&pp->children[i].process);
if (i != pp->output_owner) {
--
2.6.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] run-command: export child_process_clear()
2015-10-31 9:16 [PATCH v2 0/3] daemon: plug memory leak René Scharfe
2015-10-31 9:19 ` [PATCH v2 1/3] run-command: name the cleanup function child_process_clear() René Scharfe
@ 2015-10-31 9:20 ` René Scharfe
2015-10-31 9:20 ` [PATCH v2 3/3] daemon: plug memory leak René Scharfe
2015-10-31 13:53 ` [PATCH v2 0/3] " Jeff King
3 siblings, 0 replies; 6+ messages in thread
From: René Scharfe @ 2015-10-31 9:20 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano, Jeff King, Stefan Beller
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] daemon: plug memory leak
2015-10-31 9:16 [PATCH v2 0/3] daemon: plug memory leak René Scharfe
2015-10-31 9:19 ` [PATCH v2 1/3] run-command: name the cleanup function child_process_clear() René Scharfe
2015-10-31 9:20 ` [PATCH v2 2/3] run-command: export child_process_clear() René Scharfe
@ 2015-10-31 9:20 ` René Scharfe
2015-10-31 13:53 ` [PATCH v2 0/3] " Jeff King
3 siblings, 0 replies; 6+ messages in thread
From: René Scharfe @ 2015-10-31 9:20 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano, Jeff King, Stefan Beller
Call child_process_clear() when a child ends to release the memory
allocated for its environment. This is necessary because unlike all
other users of start_command() we don't call finish_command(), which
would have taken care of that for us.
This leak was introduced by f063d38b (daemon: use cld->env_array
when re-spawning).
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
daemon.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/daemon.c b/daemon.c
index 56679a1..be70cd4 100644
--- a/daemon.c
+++ b/daemon.c
@@ -802,6 +802,7 @@ static void check_dead_children(void)
/* remove the child */
*cradle = blanket->next;
live_children--;
+ child_process_clear(&blanket->cld);
free(blanket);
} else
cradle = &blanket->next;
--
2.6.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] daemon: plug memory leak
2015-10-31 9:16 [PATCH v2 0/3] daemon: plug memory leak René Scharfe
` (2 preceding siblings ...)
2015-10-31 9:20 ` [PATCH v2 3/3] daemon: plug memory leak René Scharfe
@ 2015-10-31 13:53 ` Jeff King
2015-10-31 20:32 ` Stefan Beller
3 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2015-10-31 13:53 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List, Junio C Hamano, Stefan Beller
On Sat, Oct 31, 2015 at 10:16:57AM +0100, René Scharfe wrote:
> Changes since v1:
> - Rebased on next, which already has a cleanup function.
> - Added first patch for renaming it.
>
> Rene Scharfe (3):
> run-command: name the cleanup function child_process_clear()
> run-command: export child_process_clear()
> daemon: plug memory leak
This round looks good to me. Thanks.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] daemon: plug memory leak
2015-10-31 13:53 ` [PATCH v2 0/3] " Jeff King
@ 2015-10-31 20:32 ` Stefan Beller
0 siblings, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2015-10-31 20:32 UTC (permalink / raw)
To: Jeff King; +Cc: René Scharfe, Git List, Junio C Hamano
On Sat, Oct 31, 2015 at 6:53 AM, Jeff King <peff@peff.net> wrote:
> On Sat, Oct 31, 2015 at 10:16:57AM +0100, René Scharfe wrote:
>
>> Changes since v1:
>> - Rebased on next, which already has a cleanup function.
>> - Added first patch for renaming it.
>>
>> Rene Scharfe (3):
>> run-command: name the cleanup function child_process_clear()
>> run-command: export child_process_clear()
>> daemon: plug memory leak
>
> This round looks good to me. Thanks.
Looks good to me, too
Thanks
Stefan
>
> -Peff
^ permalink raw reply [flat|nested] 6+ messages in thread