Commit 6278fbc5dd5467e3f66f31dc9c4bb4a1a3519ba5

Edward Thomson 2015-09-24T09:40:42

patch parsing: squash some memory leaks

diff --git a/src/patch_parse.c b/src/patch_parse.c
index 25193b6..418ed1e 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -939,6 +939,10 @@ static void patch_parsed__free(git_patch *p)
 	git__free(patch->rename_new_path);
 	git__free(patch->old_path);
 	git__free(patch->new_path);
+	git_array_clear(patch->base.hunks);
+	git_array_clear(patch->base.lines);
+	git__free(patch->base.delta);
+	git__free(patch);
 }
 
 int git_patch_from_patchfile(
@@ -985,5 +989,8 @@ int git_patch_from_patchfile(
 	*out = &patch->base;
 
 done:
+	if (error < 0)
+		patch_parsed__free(&patch->base);
+
 	return error;
 }
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index 1cf2342..c4308cb 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -847,6 +847,8 @@ void test_core_buffer__decode_base85_fails_gracefully(void)
 	cl_git_fail(git_buf_decode_base85(&buf, "truncated", 9, 42));
 	cl_assert_equal_sz(6, buf.size);
 	cl_assert_equal_s("foobar", buf.ptr);
+
+	git_buf_free(&buf);
 }
 
 void test_core_buffer__classify_with_utf8(void)