1
0
mirror of https://github.com/systemd/systemd synced 2026-03-23 23:34:52 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Luca Boccassi
a4d9c121cc
Merge pull request #20348 from poettering/free-and-replace-double-eval
make free_and_replace() double eval free
2021-07-30 11:38:13 +01:00
Lennart Poettering
0ddd5e547e xdg-autostart-service: rely on the new double-eval-free free_and_replace()
These semi-reverts 2744c7bb0176dc6b86a69acd4c449ea9e269e097
2021-07-29 21:13:03 +02:00
Lennart Poettering
7ecc424fbe alloc-util: drop double eval from free_and_replace()
Inspired by: 2744c7bb0176dc6b86a69acd4c449ea9e269e097
2021-07-29 21:12:58 +02:00
3 changed files with 12 additions and 10 deletions

View File

@ -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; \
})

View File

@ -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; \
})

View File

@ -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]);