From 7ecc424fbec9ce254655dcfd742463e849d07378 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 29 Jul 2021 21:05:38 +0200 Subject: [PATCH 1/2] alloc-util: drop double eval from free_and_replace() Inspired by: 2744c7bb0176dc6b86a69acd4c449ea9e269e097 --- src/basic/alloc-util.h | 8 +++++--- src/basic/strv.h | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 3c33308f48..0af425e491 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 911528fab4..e7654c0c0f 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; \ }) From 0ddd5e547e3d4c701a506d5c62cb6547e2d72721 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 29 Jul 2021 21:13:03 +0200 Subject: [PATCH 2/2] xdg-autostart-service: rely on the new double-eval-free free_and_replace() These semi-reverts 2744c7bb0176dc6b86a69acd4c449ea9e269e097 --- src/xdg-autostart-generator/xdg-autostart-service.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c index f21d3f54b1..501cdca0b6 100644 --- a/src/xdg-autostart-generator/xdg-autostart-service.c +++ b/src/xdg-autostart-generator/xdg-autostart-service.c @@ -416,8 +416,7 @@ int xdg_autostart_format_exec_start( if (!escaped) return log_oom(); - free_and_replace(exec_split[n], escaped); - n++; + free_and_replace(exec_split[n++], escaped); continue; } @@ -457,8 +456,7 @@ int xdg_autostart_format_exec_start( if (!quoted) return log_oom(); - free_and_replace(exec_split[n], quoted); - n++; + free_and_replace(exec_split[n++], quoted); } for (; exec_split[n]; n++) exec_split[n] = mfree(exec_split[n]);