From: Christian Brauner Date: Tue, 5 Feb 2019 05:51:55 +0000 (+0100) Subject: memory_utils: add memory_utils.h X-Git-Tag: lxc-3.2.0~164^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af1dc7cd70494c08f8edd6e2b3c176768d1ed0b0;p=thirdparty%2Flxc.git memory_utils: add memory_utils.h The header defines a simple wrapper for free() that can be used with gcc's and clang's __attribute__((__cleanup__())) macro. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 95b0a2f72..aa6368840 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -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 index 000000000..cdc95db11 --- /dev/null +++ b/src/lxc/memory_utils.h @@ -0,0 +1,32 @@ +/* liblxcapi + * + * Copyright © 2019 Christian Brauner . + * 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 + +static inline void __auto_free__(void *p) +{ + free(*(void **)p); +} + +#define __do_free __attribute__((__cleanup__(__auto_free__))) + +#endif /* __LXC_MEMORY_UTILS_H */