Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
e16ad728
Unverified
Commit
e16ad728
authored
Mar 15, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memory_utils: add call_cleaner() helper
This allows to trivially declare cleanup attributes on the fly. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
2b1ec4b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
memory_utils.h
src/lxc/memory_utils.h
+10
-7
No files found.
src/lxc/memory_utils.h
View file @
e16ad728
...
...
@@ -12,13 +12,15 @@
#include "macro.h"
#define define_cleanup_
attribute(type, func)
\
static inline void
func##_ptr
(type *ptr) \
{ \
if (*ptr) \
func(*ptr);
\
#define define_cleanup_
function(type, cleaner)
\
static inline void
cleaner##_function
(type *ptr) \
{
\
if (*ptr)
\
cleaner(*ptr);
\
}
#define call_cleaner(cleaner) __attribute__((__cleanup__(cleaner##_function)))
#define free_disarm(ptr) \
({ \
free(ptr); \
...
...
@@ -38,8 +40,9 @@ static inline void free_string_list(char **list)
free_disarm
(
list
);
}
}
define_cleanup_attribute
(
char
**
,
free_string_list
);
#define __do_free_string_list __attribute__((__cleanup__(free_string_list_ptr)))
define_cleanup_function
(
char
**
,
free_string_list
);
#define __do_free_string_list \
__attribute__((__cleanup__(free_string_list_function)))
static
inline
void
__auto_fclose__
(
FILE
**
f
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment