From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 4/6] get_helper: use run-command's internal argv_array
Date: Thu, 15 May 2014 04:34:18 -0400 [thread overview]
Message-ID: <20140515083418.GD26866@sigill.intra.peff.net> (raw)
In-Reply-To: <20140515082943.GA26473@sigill.intra.peff.net>
The get_helper functions dynamically allocates an
argv_array, feeds it to start_command, and then returns. We
then have to later clean up the memory manually after
calling finish_command. We can make this simpler by just
using run-command's internal argv_array, which handles
cleanup for us.
This also prevents a memory leak in the case that
transport_take_over is used, in which case we free the child
in finish_connect, which does not manually free the array.
Signed-off-by: Jeff King <peff@peff.net>
---
transport-helper.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/transport-helper.c b/transport-helper.c
index b468e4f..fefd34f 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -101,7 +101,6 @@ static void do_take_over(struct transport *transport)
static struct child_process *get_helper(struct transport *transport)
{
struct helper_data *data = transport->data;
- struct argv_array argv = ARGV_ARRAY_INIT;
struct strbuf buf = STRBUF_INIT;
struct child_process *helper;
const char **refspecs = NULL;
@@ -123,10 +122,9 @@ static struct child_process *get_helper(struct transport *transport)
helper->in = -1;
helper->out = -1;
helper->err = 0;
- argv_array_pushf(&argv, "git-remote-%s", data->name);
- argv_array_push(&argv, transport->remote->name);
- argv_array_push(&argv, remove_ext_force(transport->url));
- helper->argv = argv_array_detach(&argv, NULL);
+ argv_array_pushf(&helper->args, "git-remote-%s", data->name);
+ argv_array_push(&helper->args, transport->remote->name);
+ argv_array_push(&helper->args, remove_ext_force(transport->url));
helper->git_cmd = 0;
helper->silent_exec_failure = 1;
@@ -245,7 +243,6 @@ static int disconnect_helper(struct transport *transport)
close(data->helper->out);
fclose(data->out);
res = finish_command(data->helper);
- argv_array_free_detached(data->helper->argv);
free(data->helper);
data->helper = NULL;
}
--
2.0.0.rc1.436.g03cb729
next prev parent reply other threads:[~2014-05-15 8:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 8:29 [RFC/PATCH 0/6] build argv_array into run-command Jeff King
2014-05-15 8:33 ` [PATCH 1/6] run-command: store an optional argv_array Jeff King
2014-05-15 8:33 ` [PATCH 2/6] run_column_filter: use argv_array Jeff King
2014-05-15 8:34 ` [PATCH 3/6] git_connect: " Jeff King
2014-05-15 8:34 ` Jeff King [this message]
2014-05-15 8:34 ` [PATCH 5/6] get_exporter: " Jeff King
2014-05-15 8:35 ` [PATCH 6/6] get_importer: use run-command's internal argv_array Jeff King
2014-05-15 8:41 ` [PATCH 7/6] argv-array: drop "detach" code Jeff King
2014-05-15 16:48 ` [RFC/PATCH 0/6] build argv_array into run-command Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140515083418.GD26866@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).