summaryrefslogtreecommitdiff
path: root/xdiff/xpatience.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-02-16 10:15:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-02-16 18:58:05 (GMT)
commit9df0fc3d578acfdeb7fa1914fcf0507adb021fa5 (patch)
treebf6cf359e110cdb44f4cf5fe048b29e540f7b5ba /xdiff/xpatience.c
parent2b9c1209706bc2ef0ab09fb0bdc7d405e225ce8b (diff)
downloadgit-9df0fc3d578acfdeb7fa1914fcf0507adb021fa5.zip
git-9df0fc3d578acfdeb7fa1914fcf0507adb021fa5.tar.gz
git-9df0fc3d578acfdeb7fa1914fcf0507adb021fa5.tar.bz2
xdiff: fix a memory leak
Although the patience and histogram algorithms initialize the environment they do not free it if there is an error. In contrast for the Myers algorithm the environment is initalized in xdl_do_diff() and it is freed if there is an error. Fix this by always initializing the environment in xdl_do_diff() and freeing it there if there is an error. Remove the comment in do_patience_diff() about the environment being freed by xdl_diff() as it is not accurate because (a) xdl_diff() does not do that if there is an error and (b) xdl_diff() is not the only caller. Reported-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xpatience.c')
-rw-r--r--xdiff/xpatience.c4
1 files changed, 0 insertions, 4 deletions
diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c
index c5d48e8..e8de8d1 100644
--- a/xdiff/xpatience.c
+++ b/xdiff/xpatience.c
@@ -373,10 +373,6 @@ static int patience_diff(mmfile_t *file1, mmfile_t *file2,
int xdl_do_patience_diff(mmfile_t *file1, mmfile_t *file2,
xpparam_t const *xpp, xdfenv_t *env)
{
- if (xdl_prepare_env(file1, file2, xpp, env) < 0)
- return -1;
-
- /* environment is cleaned up in xdl_diff() */
return patience_diff(file1, file2, xpp, env,
1, env->xdf1.nrec, 1, env->xdf2.nrec);
}