common: add cleanup macros
authorStanislaw Wadas <s.wadas@samsung.com>
Thu, 2 Oct 2014 11:06:57 +0000 (13:06 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 14 Oct 2014 22:00:12 +0000 (00:00 +0200)
Change-Id: I6b910081bcf053ed12f6bb0a56c2eba65cc51875
Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
source/base/include/common.h

index 8a79caa..46b59b2 100644 (file)
@@ -18,6 +18,7 @@
 #define __GADGET_TOOL_COMMON_H__
 
 #include <stdlib.h>
+#include <gio/gio.h>
 
 /**
  * @brief Short program name
@@ -35,4 +36,16 @@ static inline void *zalloc(size_t size)
 
 #define ARRAY_SIZE(array) sizeof(array)/sizeof(*array)
 
+static inline void _cleanup_fn_g_free_(void *p) {
+       g_free(*(gpointer *)p);
+}
+
+static inline void _cleanup_fn_free_(void *p) {
+       free(*(void **)p);
+}
+
+#define _cleanup_(fn)   __attribute__((cleanup(fn)))
+#define _cleanup_g_free_ _cleanup_(_cleanup_fn_g_free_)
+#define _cleanup_free_  _cleanup_(_cleanup_fn_free_)
+
 #endif //__GADGET_TOOL_COMMON_H__