Skip to content

Commit 1caeacc

Browse files
torvaldsgitster
authored andcommitted
unpack_trees(): minor memory leak fix in unused destination index
This adds a "discard_index(&o->result)" to the failure path, to reclaim memory from an in-core index we built but ended up not using. The *big* memory leak comes from the fact that we leak the cache_entry things left and right. That's a very traditional and deliberate leak: because we used to build up the cache entries by just mapping them directly in from the index file (and we emulate that in modern times by allocating them from one big array), we can't actually free them one-by-one. So doing the "discard_index()" will free the hash tables etc, which is good, and it will free the "istate->alloc" but that is never set on the result because we don't get the result from the index read. So we don't actually free the individual cache entries themselves that got created from the trees. That's not something new, btw. We never did. But some day we should just add a flag to the cache_entry() that it's a "free one by one" kind, and then we could/should do it. In the meantime, this one-liner will fix *some* of the memory leaks, but not that old traditional one. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 34110cd commit 1caeacc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

unpack-trees.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
315315

316316
static int unpack_failed(struct unpack_trees_options *o, const char *message)
317317
{
318+
discard_index(&o->result);
318319
if (!o->gently) {
319320
if (message)
320321
return error(message);

0 commit comments

Comments
 (0)