From: Lucas De Marchi Date: Thu, 14 Nov 2013 02:19:15 +0000 (-0200) Subject: util: Add cleanup attribute X-Git-Tag: v16~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7aa6e23fcf69ef71d411fb154ffe6409a7a00fd;p=thirdparty%2Fkmod.git util: Add cleanup attribute --- diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index 8a70aebf..bc1ed4db 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -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 7969072d..5396598d 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)))