[libvirt] [PATCH 2/3] virSysinfoParseX86BaseBoard: Free memory upfront if no board detected

Daniel P. Berrangé berrange at redhat.com
Fri May 10 09:15:10 UTC 2019


On Fri, May 10, 2019 at 11:09:32AM +0200, Michal Privoznik wrote:
> On 5/10/19 10:08 AM, Peter Krempa wrote:
> > On Fri, May 10, 2019 at 09:52:27 +0200, Michal Privoznik wrote:
> > > If no board was detected then VIR_REALLOC_N() done at the end of
> > > the function will actually free the memory (because nborads ==
> > > 0), but @boards will be set to a non-NULL pointer. This makes it
> > > unnecessary harder for a caller to see if any board was detected.
> > 
> > Ah, yeah. Allocating 0 bytes of memory may get you a pointer.
> 
> I'm wondering if it makes sense to modify VIR_REALLOC_N() so that it calls
> VIR_FREE() if count == 0. If so, then this patch is not needed.

That would makes its behaviour different from other alocation functions,
which will none the less allocate 1 byte, if you ask for 0 bytes.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list