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.
This commit is contained in:
Lennart Poettering
2021-08-10 14:36:00 +02:00
committed by Yu Watanabe
parent 76f226d71b
commit 5afcf89ca2
2 changed files with 8 additions and 6 deletions

View File

@@ -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) \
({ \