[libvirt] [PATCH 01/14] viralloc: Adjust definition of VIR_FREE() for Coverity

Eric Blake eblake at redhat.com
Tue Jan 22 16:48:09 UTC 2013


On 01/22/2013 07:15 AM, John Ferlan wrote:
> The Coverity static analyzer was generating many false positives for the
> unary operation inside the VIR_FREE() definition as it was trying to evaluate
> the else portion of the "?:" even though the if portion was (1).

Simplifying VIR_FREE for Coverity is fine by me - we get the best of
both worlds: gcc compilation points out type mismatches, and Coverity
doesn't get confused with false positives.

> -# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
> +# if !STATIC_ANALYSIS
> +#  define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(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 *) ((const void *) &(ptr)))

However, this is too complex.  It is sufficient to do:

#  define VIR_FREE(ptr) virFree((void *) &(ptr))

ACK with that change, so I'll go ahead and push it in your name.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130122/bf0e9179/attachment-0001.sig>


More information about the libvir-list mailing list