diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-14 00:19:15 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-18 04:35:04 -0200 |
commit | d7aa6e23fcf69ef71d411fb154ffe6409a7a00fd (patch) | |
tree | 103c17366678b9741622103db47b005250577d78 | |
parent | 807c601df259d577f7a285c87d58bff8cb81ac30 (diff) | |
download | kmod-d7aa6e23fcf69ef71d411fb154ffe6409a7a00fd.tar.gz |
util: Add cleanup attribute
-rw-r--r-- | libkmod/libkmod-util.h | 7 | ||||
-rw-r--r-- | libkmod/macro.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index 8a70aeb..bc1ed4d 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -3,6 +3,7 @@ #include <limits.h> #include <stdbool.h> +#include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> @@ -56,3 +57,9 @@ static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) { return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); } + +static inline void freep(void *p) { + free(*(void**) p); +} + +#define _cleanup_free_ _cleanup_(freep) diff --git a/libkmod/macro.h b/libkmod/macro.h index 7969072..5396598 100644 --- a/libkmod/macro.h +++ b/libkmod/macro.h @@ -57,3 +57,4 @@ #define _printf_format_(a,b) __attribute__((format (printf, a, b))) #define _unused_ __attribute__((unused)) #define _always_inline_ __inline__ __attribute__((always_inline)) +#define _cleanup_(x) __attribute__((cleanup(x))) |