From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH] tools: libxl: make it illegal to pass libxl__realloc(gc) a non-gc ptr Date: Wed, 10 Feb 2016 17:44:06 +0000 Message-ID: <1455126246.7481.102.camel@citrix.com> References: <1455125223-4205-1-git-send-email-ian.campbell@citrix.com> <56BB7478.9090006@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <56BB7478.9090006@citrix.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: Andrew Cooper , ian.jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Wed, 2016-02-10 at 17:33 +0000, Andrew Cooper wrote: > On 10/02/16 17:27, Ian Campbell wrote: > > That is, if gc is not NOGC and ptr is not NULL then ptr must be > > associated gc. > > > > Currently in this case the new_ptr would not be registered with any > > gc, which Coverity rightly points out would be a memory leak. > > > > It would also be possible to fix this by adding a libxl__ptr_add() > at > > the same point, however semantically it seems like a programming > error > > to gc-realloc a pointer which is not associated with the gc in > > question, so treat it as such. > > > > Compile tested only, this change could expose latent bugs. > > > > Signed-off-by: Ian Campbell > > --- > > tools/libxl/libxl_internal.c | 7 +++++++ > > tools/libxl/libxl_internal.h | 4 +++- > > 2 files changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/tools/libxl/libxl_internal.c > b/tools/libxl/libxl_internal.c > > index 328046b..179d618 100644 > > --- a/tools/libxl/libxl_internal.c > > +++ b/tools/libxl/libxl_internal.c > > @@ -122,6 +122,13 @@ void *libxl__realloc(libxl__gc *gc, void *ptr, > size_t new_size) > > break; > > } > > } > > + /* > > + * If we get here then ptr was not previously registered > with > > + * this gc. > > + */ > > + LOG(CRITICAL, > > + "libxl__realloc on a pointer which tracked by the > given gc"); > > "is not" ? Yes. More importantly I'd somehow convinced myself that the break in the for loop went one scope further than it did. IOW this code _really_ needs an i == gc->alloc_maxsize check before it makes a fuss! At which point I may just turn it into an assert. Ian.