git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xdiff/xmerge: fix memory leak in xdl_merge
@ 2016-02-23  8:45 Patrick Steinhardt
  2016-02-23 10:09 ` Johannes Schindelin
  2016-02-23 11:59 ` [PATCH v2] " Patrick Steinhardt
  0 siblings, 2 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2016-02-23  8:45 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin, Patrick Steinhardt

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.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 xdiff/xmerge.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index d98f430..d04eb46 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -654,6 +654,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;
 	}
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-23 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23  8:45 [PATCH] xdiff/xmerge: fix memory leak in xdl_merge Patrick Steinhardt
2016-02-23 10:09 ` Johannes Schindelin
2016-02-23 11:51   ` Patrick Steinhardt
2016-02-23 11:59 ` [PATCH v2] " Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).