* [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
* Re: [PATCH] xdiff/xmerge: fix memory leak in xdl_merge
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
1 sibling, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2016-02-23 10:09 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Junio C Hamano
Hi Patrick,
On Tue, 23 Feb 2016, Patrick Steinhardt wrote:
> 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.
ACK.
I wonder, though, whether we need this in addition:
-- snipsnap --
t a/xdiff/xmerge.c b/xdiff/xmerge.c
index 625198e..e5c8745 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 ||
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] xdiff/xmerge: fix memory leak in xdl_merge
2016-02-23 10:09 ` Johannes Schindelin
@ 2016-02-23 11:51 ` Patrick Steinhardt
0 siblings, 0 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2016-02-23 11:51 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: git, Junio C Hamano
[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]
On Tue, Feb 23, 2016 at 11:09:50AM +0100, Johannes Schindelin wrote:
> Hi Patrick,
>
> On Tue, 23 Feb 2016, Patrick Steinhardt wrote:
>
> > 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.
>
> ACK.
>
> I wonder, though, whether we need this in addition:
>
> -- snipsnap --
> t a/xdiff/xmerge.c b/xdiff/xmerge.c
> index 625198e..e5c8745 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 ||
Oh, yes, this is required. I am somewhat confused by all the
pointers being passed around there, it is not immediately obvious
which pointers are being allocated and which not when you are not
intimate with the code base.
So thanks for pointing this out. Will post v2 soon.
Patrick
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] xdiff/xmerge: fix memory leak in xdl_merge
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:59 ` Patrick Steinhardt
1 sibling, 0 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2016-02-23 11:59 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.
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
xdiff/xmerge.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index d98f430..f338ad6 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -641,8 +641,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 ||
@@ -654,6 +657,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).