Backup the array passed to fetch_pack so we can free items
fetch_pack() can call remove_duplicates() on its input array and this will possibly overwrite an earlier entry with a later one if there are any duplicates in the input array. In such a case the caller here might then attempt to free an item multiple times as it goes through its cleanup. I also forgot to free the heads array we pass down into fetch_pack() when I introduced the allocation of it in this function during my builtin-fetch cleanup series. Better free it while we are here working on related memory management fixes. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shawn O. Pearce committed
Sep 14, 2007 at 18:57 UTC
e4cd6c7a20bfc776086817671d58e09060a8079a
1 file changed
+5
-2
transport.c
+5
-2
@@ -311,6 +311,7 @@ static int fetch_refs_via_pack(struct transport *transport,
311
{
312
struct git_transport_data *data = transport->data;
313
char **heads = xmalloc(nr_heads * sizeof(*heads));
314
+ char **origh = xmalloc(nr_heads * sizeof(*origh));
315
struct ref *refs;
316
char *dest = xstrdup(transport->url);
317
struct fetch_pack_args args;
@@ -329,11 +330,13 @@ static int fetch_refs_via_pack(struct transport *transport,
330
setup_fetch_pack(&args);
331
332
for (i = 0; i < nr_heads; i++)
332
- heads[i] = xstrdup(to_fetch[i]->name);
333
+ origh[i] = heads[i] = xstrdup(to_fetch[i]->name);
334
refs = fetch_pack(dest, nr_heads, heads, &transport->pack_lockfile);
335
336
for (i = 0; i < nr_heads; i++)
336
- free(heads[i]);
337
+ free(origh[i]);
338
+ free(origh);
339
+ free(heads);
340
free_refs(refs);
341
free(dest);
342
return 0;