summaryrefslogtreecommitdiff
path: root/src/basic/alloc-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-08-10 14:36:00 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-08-11 04:47:10 +0900
commit5afcf89ca29b518eb2fa244b015afc2708f77e1d (patch)
tree9eab9ddad63b6d7aa0592d3f43e12dbae70b08cb /src/basic/alloc-util.h
parent76f226d71b9d8d36eb4e61285e80527637299fac (diff)
downloadsystemd-5afcf89ca29b518eb2fa244b015afc2708f77e1d.tar.gz
alloc-util: make mfree() typesafe
Make sure we return the same type as we accept. One incorrect use of mfree() is discovered and fixed this way.
Diffstat (limited to 'src/basic/alloc-util.h')
-rw-r--r--src/basic/alloc-util.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
index 0af425e491..e587fe79e7 100644
--- a/src/basic/alloc-util.h
+++ b/src/basic/alloc-util.h
@@ -44,10 +44,11 @@ typedef void (*free_func_t)(void *p);
#define malloc0(n) (calloc(1, (n) ?: 1))
-static inline void *mfree(void *memory) {
- free(memory);
- return NULL;
-}
+#define mfree(memory) \
+ ({ \
+ free(memory); \
+ (typeof(memory)) NULL; \
+ })
#define free_and_replace(a, b) \
({ \