tree-wide: Introduce free_and_replace_full()

Let's have all our free_and_replace() functions use a single
implementation.
This commit is contained in:
Daan De Meyer
2022-07-21 09:45:55 +09:00
committed by Yu Watanabe
parent 4a0cb5474e
commit fc4c10b28b
4 changed files with 8 additions and 22 deletions
+5 -2
View File
@@ -50,16 +50,19 @@ typedef void* (*mfree_func_t)(void *p);
#define malloc0(n) (calloc(1, (n) ?: 1))
#define free_and_replace(a, b) \
#define free_and_replace_full(a, b, free_func) \
({ \
typeof(a)* _a = &(a); \
typeof(b)* _b = &(b); \
free(*_a); \
free_func(*_a); \
*_a = *_b; \
*_b = NULL; \
0; \
})
#define free_and_replace(a, b) \
free_and_replace_full(a, b, free)
void* memdup(const void *p, size_t l) _alloc_(2);
void* memdup_suffix0(const void *p, size_t l); /* We can't use _alloc_() here, since we return a buffer one byte larger than the specified size */