Commit 323bb885 by Carlos Martín Nieto

Fix a few leaks

`git_diff_get_patch()` would unconditionally load the patch object and
then simply leak it if the user hadn't requested it. Short-circuit
loading the object if the user doesn't want it.

The rest of the plugs are simply calling the free functions of objects
allocated during the tests.
parent dce5f26f
...@@ -1509,6 +1509,10 @@ int git_diff_get_patch( ...@@ -1509,6 +1509,10 @@ int git_diff_get_patch(
if (git_diff_delta__should_skip(ctxt.opts, delta)) if (git_diff_delta__should_skip(ctxt.opts, delta))
return 0; return 0;
/* Don't load the patch if the user doesn't want it */
if (!patch_ptr)
return 0;
patch = diff_patch_alloc(&ctxt, delta); patch = diff_patch_alloc(&ctxt, delta);
if (!patch) if (!patch)
return -1; return -1;
......
...@@ -239,6 +239,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void) ...@@ -239,6 +239,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
git_diff_patch_free(patch); git_diff_patch_free(patch);
git_diff_list_free(diff); git_diff_list_free(diff);
git_tree_free(head); git_tree_free(head);
git_config_free(cfg);
} }
static void check_single_patch_stats( static void check_single_patch_stats(
...@@ -310,4 +311,5 @@ void test_diff_patch__line_counts_with_eofnl(void) ...@@ -310,4 +311,5 @@ void test_diff_patch__line_counts_with_eofnl(void)
check_single_patch_stats(g_repo, 1, 1, 1); check_single_patch_stats(g_repo, 1, 1, 1);
git_buf_free(&content); git_buf_free(&content);
git_config_free(cfg);
} }
...@@ -274,6 +274,7 @@ void test_diff_rename__not_exact_match(void) ...@@ -274,6 +274,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]); cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
git_diff_list_free(diff);
/* git diff -M -C \ /* git diff -M -C \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \ * 1c068dee5790ef1580cfc4cd670915b48d790084 \
......
...@@ -169,4 +169,6 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) ...@@ -169,4 +169,6 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
cl_assert_equal_i( cl_assert_equal_i(
true, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); true, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);
git_object_free(next_top_stash);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment