diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-12 15:43:30 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-16 14:13:25 +0100 |
commit | c66ee23f73a0b8e4056abf4a2a463ae48346f249 (patch) | |
tree | 0bf273af7eb4874365f0bd84a7b4db7a8dc747ea | |
parent | ad45d232fee8157baadb799f3867ddec95e2ef91 (diff) | |
download | NetworkManager-c66ee23f73a0b8e4056abf4a2a463ae48346f249.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.h | 2 | ||||
-rw-r--r-- | shared/nm-macros-internal.h | 10 |
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) /********************************************************/ |