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__(<cleanup-fun>))) macro. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0220bdda
...@@ -21,6 +21,7 @@ noinst_HEADERS = api_extensions.h \ ...@@ -21,6 +21,7 @@ noinst_HEADERS = api_extensions.h \
lxc.h \ lxc.h \
lxclock.h \ lxclock.h \
macro.h \ macro.h \
memory_utils.h \
monitor.h \ monitor.h \
namespace.h \ namespace.h \
raw_syscalls.h \ raw_syscalls.h \
...@@ -112,6 +113,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \ ...@@ -112,6 +113,7 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \
lxclock.c lxclock.h \ lxclock.c lxclock.h \
lxcseccomp.h \ lxcseccomp.h \
macro.h \ macro.h \
memory_utils.h \
mainloop.c mainloop.h \ mainloop.c mainloop.h \
namespace.c namespace.h \ namespace.c namespace.h \
nl.c nl.h \ nl.c nl.h \
......
/* 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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment