git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] xdiff/xmerge: fix memory leak in xdl_merge
Date: Tue, 23 Feb 2016 12:51:35 +0100	[thread overview]
Message-ID: <20160223115135.GA977@pks-pc.localdomain> (raw)
In-Reply-To: <alpine.DEB.2.20.1602231108260.3152@virtualbox>

[-- 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 --]

  reply	other threads:[~2016-02-23 11:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-02-23 11:59 ` [PATCH v2] " Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160223115135.GA977@pks-pc.localdomain \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).