diff: fix leaks in diff printing
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/src/diff_patch.c b/src/diff_patch.c
index ec4979a..0628da6 100644
--- a/src/diff_patch.c
+++ b/src/diff_patch.c
@@ -325,9 +325,14 @@ static int diff_binary(git_diff_output *output, git_patch *patch)
old_data, old_len, new_data, new_len)) < 0)
return error;
- return giterr_set_after_callback_function(
+ error = giterr_set_after_callback_function(
output->binary_cb(patch->delta, &binary, output->payload),
"git_patch");
+
+ git__free((char *) binary.old_file.data);
+ git__free((char *) binary.new_file.data);
+
+ return error;
}
static int diff_patch_generate(git_patch *patch, git_diff_output *output)
@@ -377,6 +382,9 @@ static void diff_patch_free(git_patch *patch)
git__free((char *)patch->diff_opts.old_prefix);
git__free((char *)patch->diff_opts.new_prefix);
+ git__free((char *)patch->binary.old_file.data);
+ git__free((char *)patch->binary.new_file.data);
+
if (patch->flags & GIT_DIFF_PATCH_ALLOCATED)
git__free(patch);
}
diff --git a/src/diff_print.c b/src/diff_print.c
index c586983..546488c 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -578,6 +578,9 @@ int git_diff_print(
giterr_set_after_callback_function(error, "git_diff_print");
}
+ git__free(pi.nfile);
+ git__free(pi.ofile);
+
git_buf_free(&buf);
return error;
diff --git a/tests/diff/binary.c b/tests/diff/binary.c
index 6a5f390..3a57168 100644
--- a/tests/diff/binary.c
+++ b/tests/diff/binary.c
@@ -4,6 +4,7 @@
#include "buffer.h"
#include "filebuf.h"
+#include "repository.h"
static git_repository *repo;
@@ -497,7 +498,7 @@ void test_diff_binary__blob_to_blob(void)
opts.id_abbrev = GIT_OID_HEXSZ;
repo = cl_git_sandbox_init("renames");
- cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_repository_index__weakptr(&index, repo));
cl_git_append2file("renames/untimely.txt", "Oh that crazy Kipling!\r\n");
cl_git_pass(git_index_add_bypath(index, "untimely.txt"));
@@ -532,4 +533,7 @@ void test_diff_binary__blob_to_blob(void)
git__free(diff_data.old_path);
git__free(diff_data.new_path);
+
+ git_buf_free(&diff_data.old_binary_base85);
+ git_buf_free(&diff_data.new_binary_base85);
}