Commit ae26c4b80f6d144df0e7915f72c64c5daf73ca50

Vicent Martí 2013-11-05T06:55:29

Merge pull request #1943 from libgit2/ntk/fix/leaks Fix leaks

diff --git a/src/config_file.c b/src/config_file.c
index 9b4a7c1..0bd4e4e 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1210,8 +1210,11 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
 	write_start = data_start;
 
 	/* Lock the file */
-	if ((result = git_filebuf_open(&file, cfg->file_path, 0, GIT_CONFIG_FILE_MODE)) < 0)
-		return result;
+	if ((result = git_filebuf_open(
+		&file, cfg->file_path, 0, GIT_CONFIG_FILE_MODE)) < 0) {
+			git_buf_free(&reader->buffer);
+			return result;
+	}
 
 	skip_bom(reader);
 	ldot = strrchr(key, '.');
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index df31e73..7cc0322 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -1477,6 +1477,8 @@ void test_diff_workdir__with_stale_index(void)
 	cl_git_pass(git_diff_foreach(
 		diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
 
+	git_diff_free(diff);
+
 	cl_assert_equal_i(16, exp.files);
 	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
 	cl_assert_equal_i(3, exp.file_status[GIT_DELTA_DELETED]);