unpack-trees: free cache_entry array members for merges

The merge functions duplicate entries as needed and they don't free them. Release them in unpack_nondirectories, the same function where they were allocated, after we're done. As suggested by Felipe, use the same loop style (zero-based for loop) for freeing as for allocating. Improved-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 2, 2013 at 17:46 UTC 5d80ef5a6e727bbecd7d892a5043bae25f7ca5e2
1 file changed +10 -3
unpack-trees.c
+10 -3
@@ -600,9 +600,16 @@ static int unpack_nondirectories(int n, unsigned long mask,
600 src[i + o->merge] = create_ce_entry(info, names + i, stage);
601 }
602
603 - if (o->merge)
604 - return call_unpack_fn((const struct cache_entry * const *)src,
605 - o);
603 + if (o->merge) {
604 + int rc = call_unpack_fn((const struct cache_entry * const *)src,
605 + o);
606 + for (i = 0; i < n; i++) {
607 + struct cache_entry *ce = src[i + o->merge];
608 + if (ce != o->df_conflict_entry)
609 + free(ce);
610 + }
611 + return rc;
612 + }
613
614 for (i = 0; i < n; i++)
615 if (src[i] && src[i] != o->df_conflict_entry)