aboutsummaryrefslogtreecommitdiff
path: root/xdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-02-23 12:59:17 +0100
committerJunio C Hamano <gitster@pobox.com>2016-02-23 12:58:26 -0800
commit4867f1184c943f7738bb7b42cab2e62cf16cdb18 (patch)
tree170a9a156b6e224cfa133f7182363e02b44f0f14 /xdiff
parent833e48259e23aea76f3765d28d1b2200332301f7 (diff)
downloadgit-4867f1184c943f7738bb7b42cab2e62cf16cdb18.tar.gz
git-4867f1184c943f7738bb7b42cab2e62cf16cdb18.tar.xz
xdiff/xmerge: fix memory leak in xdl_merge
When building the script for the second file that is to be merged we have already allocated memory for data structures related to the first file. When we encounter an error in building the second script we only free allocated memory related to the second file before erroring out. Fix this memory leak by also releasing allocated memory related to the first file. Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff')
-rw-r--r--xdiff/xmerge.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 625198e05..e272424cf 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -579,8 +579,11 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
result->ptr = NULL;
result->size = 0;
- if (xdl_do_diff(orig, mf1, xpp, &xe1) < 0 ||
- xdl_do_diff(orig, mf2, xpp, &xe2) < 0) {
+ if (xdl_do_diff(orig, mf1, xpp, &xe1) < 0) {
+ return -1;
+ }
+ if (xdl_do_diff(orig, mf2, xpp, &xe2) < 0) {
+ xdl_free_env(&xe1);
return -1;
}
if (xdl_change_compact(&xe1.xdf1, &xe1.xdf2, xpp->flags) < 0 ||
@@ -592,6 +595,8 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
if (xdl_change_compact(&xe2.xdf1, &xe2.xdf2, xpp->flags) < 0 ||
xdl_change_compact(&xe2.xdf2, &xe2.xdf1, xpp->flags) < 0 ||
xdl_build_script(&xe2, &xscr2) < 0) {
+ xdl_free_script(xscr1);
+ xdl_free_env(&xe1);
xdl_free_env(&xe2);
return -1;
}