@matheusbsbs / matheus-bagliano / commits / 1ce584b058
Fork 0

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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Aug 9, 2010 at 22:33 UTC 1ce584b05843dfa8b0fe31ed3d75bddf1c29c4e0
1 file changed +6 -1
unpack-trees.c
+6 -1
@@ -329,6 +329,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
329 {
330 int i, ret, bottom;
331 struct tree_desc t[MAX_UNPACK_TREES];
332 + void *buf[MAX_UNPACK_TREES];
333 struct traverse_info newinfo;
334 struct name_entry *p;
335
@@ -346,12 +347,16 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
347 const unsigned char *sha1 = NULL;
348 if (dirmask & 1)
349 sha1 = names[i].sha1;
349 - fill_tree_descriptor(t+i, sha1);
350 + buf[i] = fill_tree_descriptor(t+i, sha1);
351 }
352
353 bottom = switch_cache_bottom(&newinfo);
354 ret = traverse_trees(n, t, &newinfo);
355 restore_cache_bottom(&newinfo, bottom);
356 +
357 + for (i = 0; i < n; i++)
358 + free(buf[i]);
359 +
360 return ret;
361 }
362