Re: [PATCH] xdiff/xmerge: fix memory leak in xdl_merge

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]