Commit d7fc2eb29b4574b96b190572470bfcb7dab9d078

wilke 2013-09-13T21:36:39

Fix memory leak in git_tree_walk on error or when stopping the walk from the supplied callback

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/src/tree.c b/src/tree.c
index cd8adfb..0bdf9a9 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -907,11 +907,12 @@ static int tree_walk(
 				return -1;
 
 			error = tree_walk(subtree, callback, path, payload, preorder);
+			git_tree_free(subtree);
+
 			if (error != 0)
 				break;
 
 			git_buf_truncate(path, path_len);
-			git_tree_free(subtree);
 		}
 
 		if (!preorder && callback(path->ptr, entry, payload) < 0) {