From c66ee23f73a0b8e4056abf4a2a463ae48346f249 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Feb 2016 15:43:30 +0100 Subject: [PATCH] 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. --- shared/nm-default.h | 2 ++ shared/nm-macros-internal.h | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 + #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) /********************************************************/