Commit 236945a524b845d9b419fbf6861d36bbc7e57b56

Russell Belfer 2013-09-13T14:31:26

Merge pull request #1849 from whavinga/treewalker Treewalker

diff --git a/src/tree.c b/src/tree.c
index f946919..0bdf9a9 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -881,8 +881,10 @@ static int tree_walk(
 	git_vector_foreach(&tree->entries, i, entry) {
 		if (preorder) {
 			error = callback(path->ptr, entry, payload);
-			if (error > 0)
+			if (error > 0) {
+				error = 0;
 				continue;
+			}
 			if (error < 0) {
 				giterr_clear();
 				return GIT_EUSER;
@@ -905,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) {