]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
memory_utils: add memory_utils.h
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 5 Feb 2019 05:51:55 +0000 (06:51 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 6 Feb 2019 10:44:09 +0000 (11:44 +0100)
The header defines a simple wrapper for free() that can be used with
gcc's and clang's __attribute__((__cleanup__(<cleanup-fun>))) macro.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/Makefile.am
src/lxc/memory_utils.h [new file with mode: 0644]

index 95b0a2f724fc439214660fc3a66495f40b198188..aa6368840ef1ead27590ad35d055d5e3025ce1b0 100644 (file)
@@ -21,6 +21,7 @@ noinst_HEADERS = api_extensions.h \
                 lxc.h \
                 lxclock.h \
                 macro.h \
+                memory_utils.h \
                 monitor.h \
                 namespace.h \
                 raw_syscalls.h \
@@ -112,6 +113,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \
                    lxclock.c lxclock.h \
                    lxcseccomp.h \
                    macro.h \
+                   memory_utils.h \
                    mainloop.c mainloop.h \
                    namespace.c namespace.h \
                    nl.c nl.h \
diff --git a/src/lxc/memory_utils.h b/src/lxc/memory_utils.h
new file mode 100644 (file)
index 0000000..cdc95db
--- /dev/null
@@ -0,0 +1,32 @@
+/* liblxcapi
+ *
+ * Copyright © 2019 Christian Brauner <christian.brauner@ubuntu.com>.
+ * Copyright © 2019 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __LXC_MEMORY_UTILS_H
+#define __LXC_MEMORY_UTILS_H
+
+#include <stdlib.h>
+
+static inline void __auto_free__(void *p)
+{
+       free(*(void **)p);
+}
+
+#define __do_free __attribute__((__cleanup__(__auto_free__)))
+
+#endif /* __LXC_MEMORY_UTILS_H */