Merge pull request #2299 from mekishizufu/fix_leaks Plug some leaks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/filter.c b/src/filter.c
index ff81eb1..b2f5796 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -617,7 +617,7 @@ int git_filter_list_apply_to_data(
si = di; /* swap buffers */
} else {
tgt->size = 0;
- return error;
+ goto cleanup;
}
}
@@ -625,9 +625,10 @@ int git_filter_list_apply_to_data(
if (si != 1)
git_buf_swap(dbuffer[0], dbuffer[1]);
+cleanup:
git_buf_free(&local); /* don't leak if we allocated locally */
- return 0;
+ return error;
}
int git_filter_list_apply_to_file(
diff --git a/tests/reset/default.c b/tests/reset/default.c
index ecb3e7f..c76f148 100644
--- a/tests/reset/default.c
+++ b/tests/reset/default.c
@@ -185,23 +185,20 @@ void test_reset_default__resetting_unknown_filepaths_does_not_fail(void)
void test_reset_default__staged_rename_reset_delete(void)
{
- git_index *idx;
git_index_entry entry;
const git_index_entry *existing;
char *paths[] = { "new.txt" };
initialize("testrepo2");
- cl_git_pass(git_repository_index(&idx, _repo));
-
- existing = git_index_get_bypath(idx, "new.txt", 0);
+ existing = git_index_get_bypath(_index, "new.txt", 0);
cl_assert(existing);
memcpy(&entry, existing, sizeof(entry));
- cl_git_pass(git_index_remove_bypath(idx, "new.txt"));
+ cl_git_pass(git_index_remove_bypath(_index, "new.txt"));
entry.path = "renamed.txt";
- cl_git_pass(git_index_add(idx, &entry));
+ cl_git_pass(git_index_add(_index, &entry));
_pathspecs.strings = paths;
_pathspecs.count = 1;