]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: Add cleanup attribute
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 14 Nov 2013 02:19:15 +0000 (00:19 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 18 Nov 2013 06:35:04 +0000 (04:35 -0200)
libkmod/libkmod-util.h
libkmod/macro.h

index 8a70aebf66694dcfb3d5cfbf146e3dd75176ed52..bc1ed4db8279ff32b553faa3611099c772272f88 100644 (file)
@@ -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)
index 7969072dd95cad4bf406c58050da62771ad27529..5396598d935a4738912c2c48e1702514a6802eb5 100644 (file)
@@ -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)))