Skip to content

Commit 1ce584b

Browse files
jrngitster
authored andcommitted
read-tree: stop leaking tree objects
The underlying problem is that the fill_tree_descriptor() API is easy to misuse, and this patch does not fix that. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59efba6 commit 1ce584b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

unpack-trees.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
329329
{
330330
int i, ret, bottom;
331331
struct tree_desc t[MAX_UNPACK_TREES];
332+
void *buf[MAX_UNPACK_TREES];
332333
struct traverse_info newinfo;
333334
struct name_entry *p;
334335

@@ -346,12 +347,16 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
346347
const unsigned char *sha1 = NULL;
347348
if (dirmask & 1)
348349
sha1 = names[i].sha1;
349-
fill_tree_descriptor(t+i, sha1);
350+
buf[i] = fill_tree_descriptor(t+i, sha1);
350351
}
351352

352353
bottom = switch_cache_bottom(&newinfo);
353354
ret = traverse_trees(n, t, &newinfo);
354355
restore_cache_bottom(&newinfo, bottom);
356+
357+
for (i = 0; i < n; i++)
358+
free(buf[i]);
359+
355360
return ret;
356361
}
357362

0 commit comments

Comments
 (0)