[libvirt] [libvirt-php][PATCH 4/7] util: Introduce VIR_FREE

Michal Privoznik posted 7 patches 7 years, 5 months ago
[libvirt] [libvirt-php][PATCH 4/7] util: Introduce VIR_FREE
Posted by Michal Privoznik 7 years, 5 months ago
Just like libvirt has it. After freeing pointer set it to NULL to
avoid double frees.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/util.h b/src/util.h
index fcd4075..3af77d4 100644
--- a/src/util.h
+++ b/src/util.h
@@ -36,6 +36,12 @@
 # define DPRINTF(fmt, ...)      \
     debugPrint(debugSource, fmt, __VA_ARGS__)
 
+# define VIR_FREE(ptr) \
+    do { \
+        free(ptr); \
+        ptr = NULL; \
+    } while (0)
+
 # define ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(array[0]))
 
 # define IS_BIGENDIAN (*(uint16_t *)"\0\xff" < 0x100)
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-php][PATCH 4/7] util: Introduce VIR_FREE
Posted by Erik Skultety 7 years, 5 months ago
On Thu, Dec 07, 2017 at 10:22:59AM +0100, Michal Privoznik wrote:
> Just like libvirt has it. After freeing pointer set it to NULL to
> avoid double frees.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Reviewed-by: Erik Skultety <eskultet@redhat.com>

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