macros: add nm_auto_free macro
authorThomas Haller <thaller@redhat.com>
Fri, 12 Feb 2016 14:43:30 +0000 (15:43 +0100)
committerThomas Haller <thaller@redhat.com>
Tue, 16 Feb 2016 13:13:25 +0000 (14:13 +0100)
Similar to gs_free to cleanup pointers with free(). Note that
g_free() and free() cannot be used interchangably.

shared/nm-default.h
shared/nm-macros-internal.h

index f1fcb84..72b74a5 100644 (file)
@@ -41,6 +41,8 @@
 
 /* always include these headers for our internal source files. */
 
+#include <stdlib.h>
+
 #include "nm-glib.h"
 #include "nm-version.h"
 #include "gsystem-local-alloc.h"
index 63f5138..4d80274 100644 (file)
 #ifndef __NM_MACROS_INTERNAL_H__
 #define __NM_MACROS_INTERNAL_H__
 
-#include "nm-default.h"
+/********************************************************/
+
+/**
+ * nm_auto_free:
+ *
+ * Call free() on a variable location when it goes out of scope.
+ */
+#define nm_auto_free __attribute__ ((cleanup(_nm_auto_free_impl)))
+GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free)
 
 /********************************************************/