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

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



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


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