get_helper: use run-command's internal argv_array
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 15, 2014 at 04:34 UTC
e0ab2ac6c553cbba5d0275cfd35beb3351cae034
1 file changed
+3
-6
transport-helper.c
+3
-6
@@ -101,7 +101,6 @@ static void do_take_over(struct transport *transport)
101
static struct child_process *get_helper(struct transport *transport)
102
{
103
struct helper_data *data = transport->data;
104
- struct argv_array argv = ARGV_ARRAY_INIT;
104
struct strbuf buf = STRBUF_INIT;
105
struct child_process *helper;
106
const char **refspecs = NULL;
@@ -123,10 +122,9 @@ static struct child_process *get_helper(struct transport *transport)
122
helper->in = -1;
123
helper->out = -1;
124
helper->err = 0;
126
- argv_array_pushf(&argv, "git-remote-%s", data->name);
127
- argv_array_push(&argv, transport->remote->name);
128
- argv_array_push(&argv, remove_ext_force(transport->url));
129
- helper->argv = argv_array_detach(&argv, NULL);
125
+ argv_array_pushf(&helper->args, "git-remote-%s", data->name);
126
+ argv_array_push(&helper->args, transport->remote->name);
127
+ argv_array_push(&helper->args, remove_ext_force(transport->url));
128
helper->git_cmd = 0;
129
helper->silent_exec_failure = 1;
130
@@ -245,7 +243,6 @@ static int disconnect_helper(struct transport *transport)
243
close(data->helper->out);
244
fclose(data->out);
245
res = finish_command(data->helper);
248
- argv_array_free_detached(data->helper->argv);
246
free(data->helper);
247
data->helper = NULL;
248
}