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

Michal Privoznik mprivozn at redhat.com
Fri May 10 09:09:32 UTC 2019


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.

Michal




More information about the libvir-list mailing list