From: Ian Campbell Subject: Re: [PATCH for-4.5] libxc: don't leak buffer containing the uncompressed PV kernel Date: Mon, 17 Nov 2014 09:36:01 +0000 Message-ID: <1416216961.27385.3.camel@citrix.com> References: <1415621313-25835-1-git-send-email-ian.campbell@citrix.com> <20141117091658.GD11070@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20141117091658.GD11070@zion.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Mon, 2014-11-17 at 09:16 +0000, Wei Liu wrote: > > @@ -508,6 +522,10 @@ static int xc_try_lzo1x_decode( > > if ( out_len != dst_len ) > > break; > > > > + msg = "Error registering stream output"; > > + if ( xc_dom_register_external(dom, out_buf, out_len) ) > > + break; > > + > > Is this hunk problematic? > > It's called in a loop. Looks like it may register the same ptr multiple > times which leads to freeing same ptr multiple times later. Yes, it is wrong. I mistakenly read this as being the "input stream done" case, but it's just "a chunk is done". I think the right place to add this new code is actually in the if true part of: dst_len = lzo_read_32(cur); if ( !dst_len ) return 0; That's the only return within the loop, and any break would take us to the function epilogue which is the error case and frees the buffer. Thanks for checking! Ian.