summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-02-12 15:43:30 +0100
committerThomas Haller <thaller@redhat.com>2016-02-16 11:35:49 +0100
commitaf3e4d30187115e5d84d18a8d21ab9a94fe5313d (patch)
tree9bc3777d1e5ce49044e6b825222f0e71557a3106
parenta058cf41dc8dd6f952c4652ae689f3ed8ac042d6 (diff)
downloadNetworkManager-af3e4d30187115e5d84d18a8d21ab9a94fe5313d.tar.gz
macros: add nm_auto_free macro
Similar to gs_free to cleanup pointers with free(). Note that g_free() and free() cannot be used interchangably.
-rw-r--r--shared/nm-default.h2
-rw-r--r--shared/nm-macros-internal.h10
2 files changed, 11 insertions, 1 deletions
diff --git a/shared/nm-default.h b/shared/nm-default.h
index f1fcb845e4..72b74a5493 100644
--- a/shared/nm-default.h
+++ b/shared/nm-default.h
@@ -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"
diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h
index 63f513847a..4d802746ba 100644
--- a/shared/nm-macros-internal.h
+++ b/shared/nm-macros-internal.h
@@ -22,7 +22,15 @@
#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)
/********************************************************/