[PATCH] util: warn when passing a non-pointer to VIR_FREE

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

 



There were recently some bugs where VIR_FREE was called with an
int parameter. Try to affect the value passed to VIR_FREE to
a const void* so that the compiler gets a chance to emit a warning
if we didn't pass a pointer to VIR_FREE.
---
 src/util/memory.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/util/memory.h b/src/util/memory.h
index 66b4c42..fab425d 100644
--- a/src/util/memory.h
+++ b/src/util/memory.h
@@ -197,7 +197,11 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
  * Free the memory stored in 'ptr' and update to point
  * to NULL.
  */
-# define VIR_FREE(ptr) virFree(&(ptr))
+# define VIR_FREE(ptr)                                   \
+    do {                                                 \
+        ATTRIBUTE_UNUSED const void *check_type = (ptr); \
+        virFree(&(ptr));                                 \
+    } while (0)
 
 
 # if TEST_OOM
-- 
1.7.4.4

--
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]