]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
viralloc: Adjust definition of VIR_FREE() for Coverity
authorJohn Ferlan <jferlan@redhat.com>
Tue, 22 Jan 2013 14:15:37 +0000 (09:15 -0500)
committerEric Blake <eblake@redhat.com>
Tue, 22 Jan 2013 17:19:43 +0000 (10:19 -0700)
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).

Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/viralloc.h

index 37ec5ee8943f9fc1b36a7b8398210b098cd83477..e1f5758f045e32c82e77b6b397addbeb0833417d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * viralloc.h: safer memory allocation
  *
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2013 Red Hat, Inc.
  * Copyright (C) 2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -361,11 +361,21 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
  * Free the memory stored in 'ptr' and update to point
  * to NULL.
  */
+# if !STATIC_ANALYSIS
 /* The ternary ensures that ptr is a pointer and not an integer type,
- * while evaluating ptr only once.  For now, we intentionally cast
+ * while evaluating ptr only once.  This gives us extra compiler
+ * safety when compiling under gcc.  For now, we intentionally cast
  * away const, since a number of callers safely pass const char *.
  */
-# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
+#  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 *) &(ptr))
+# endif
+
 
 
 # if TEST_OOM