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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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).
---
 src/util/viralloc.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 37ec5ee..0c9b177 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -365,7 +365,16 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
  * while evaluating ptr only once.  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)))
+# 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)))
+# endif
+
 
 
 # if TEST_OOM
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]