summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-07-30 12:38:13 +0200
committerGitHub <noreply@github.com>2021-07-30 12:38:13 +0200
commita4d9c121cc011d3a4feeaa74f54a69de8c9b0b20 (patch)
tree0297a2ed6454305dc25d6b3eee64d4458df76dd9 /src
parenttest: correctly detect ASan on s390x (diff)
parentxdg-autostart-service: rely on the new double-eval-free free_and_replace() (diff)
downloadsystemd-a4d9c121cc011d3a4feeaa74f54a69de8c9b0b20.tar.xz
systemd-a4d9c121cc011d3a4feeaa74f54a69de8c9b0b20.zip
Merge pull request #20348 from poettering/free-and-replace-double-eval
make free_and_replace() double eval free
Diffstat (limited to 'src')
-rw-r--r--src/basic/alloc-util.h8
-rw-r--r--src/basic/strv.h8
-rw-r--r--src/xdg-autostart-generator/xdg-autostart-service.c6
3 files changed, 12 insertions, 10 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; \
})
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]);