[libvirt] [PATCH 2/4] viralloc: Honor const correctness in VIR_FREE

John Ferlan jferlan at redhat.com
Tue Jul 15 13:47:59 UTC 2014



On 07/15/2014 09:41 AM, Eric Blake wrote:

<...snip...>

> 
> This definition was doing two things - casting away const, AND doing
> type validation.  virFree(&foo) will compile even if foo is an int, but
> we want to ensure that foo is of type char*.
> 
> I think what you want is:
> 
> #  define VIR_FREE(ptr) virFree(1 ? &(ptr) : (ptr))
> 
>> -# else
>> -/* The Coverity static analyzer considers the else path of the "?:" and
>> - * flags the VIR_FREE() of the address of the address of memory as a
>> - * RESOURCE_LEAK resulting in numerous false positives (eg, VIR_FREE(&ptr))
>> - */
>> -#  define VIR_FREE(ptr) virFree((void *) &(ptr))
> 
> and keep this alternative to hush up coverity.
> 
> 

FWIW: I got notice a couple weeks ago that Coverity 7.5.0 (released June
27, 2014) has a fix for this issue.

Since there's no "guarantee" that everyone who runs a Coverity scan will
update to that new version - I'd be hesitant to say that we could just
do away with it since without this "condition"- Coverity will be very noisy.

John




More information about the libvir-list mailing list