From: Lennart Poettering Date: Thu, 29 Jul 2021 19:05:38 +0000 (+0200) Subject: alloc-util: drop double eval from free_and_replace() X-Git-Tag: v250-rc1~899^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ecc424fbec9ce254655dcfd742463e849d07378;p=thirdparty%2Fsystemd.git alloc-util: drop double eval from free_and_replace() Inspired by: 2744c7bb0176dc6b86a69acd4c449ea9e269e097 --- diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 3c33308f481..0af425e4914 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -51,9 +51,11 @@ static inline void *mfree(void *memory) { #define free_and_replace(a, b) \ ({ \ - free(a); \ - (a) = (b); \ - (b) = NULL; \ + typeof(a)* _a = &(a); \ + typeof(b)* _b = &(b); \ + free(*_a); \ + (*_a) = (*_b); \ + (*_b) = NULL; \ 0; \ }) diff --git a/src/basic/strv.h b/src/basic/strv.h index 911528fab49..e7654c0c0ff 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -233,9 +233,11 @@ int fputstrv(FILE *f, char * const *l, const char *separator, bool *space); #define strv_free_and_replace(a, b) \ ({ \ - strv_free(a); \ - (a) = (b); \ - (b) = NULL; \ + char ***_a = &(a); \ + char ***_b = &(b); \ + strv_free(*_a); \ + (*_a) = (*_b); \ + (*_b) = NULL; \ 0; \ })