summaryrefslogtreecommitdiff
path: root/src/xdg-autostart-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-05-18 23:01:32 +0200
committerLennart Poettering <lennart@poettering.net>2021-05-19 16:42:37 +0200
commit319a4f4bc46b230fc660321e99aaac1bc449deea (patch)
tree9eca2e1352df29aeeef91e4fd4bcc12ad4ea44e9 /src/xdg-autostart-generator
parent99480504d47c0a6bbb1ac230cc33df12bbd36c54 (diff)
downloadsystemd-319a4f4bc46b230fc660321e99aaac1bc449deea.tar.gz
alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()
We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
Diffstat (limited to 'src/xdg-autostart-generator')
-rw-r--r--src/xdg-autostart-generator/xdg-autostart-service.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c
index 00d8b76539..5068c0ebb3 100644
--- a/src/xdg-autostart-generator/xdg-autostart-service.c
+++ b/src/xdg-autostart-generator/xdg-autostart-service.c
@@ -188,7 +188,6 @@ static int strv_strndup_unescape_and_push(
const char *filename,
unsigned line,
char ***sv,
- size_t *n_allocated,
size_t *n,
const char *start,
const char *end) {
@@ -207,7 +206,7 @@ static int strv_strndup_unescape_and_push(
if (r < 0)
return r;
- if (!greedy_realloc((void**) sv, n_allocated, *n + 2, sizeof(char*))) /* One extra for NULL */
+ if (!GREEDY_REALLOC(*sv, *n + 2)) /* One extra for NULL */
return log_oom();
(*sv)[*n] = TAKE_PTR(copy);
@@ -243,10 +242,10 @@ static int xdg_config_parse_strv(
return 0;
}
- size_t n = 0, n_allocated = 0;
+ size_t n = 0;
_cleanup_strv_free_ char **sv = NULL;
- if (!GREEDY_REALLOC0(sv, n_allocated, 1))
+ if (!GREEDY_REALLOC0(sv, 1))
return log_oom();
/* We cannot use strv_split because it does not handle escaping correctly. */
@@ -265,7 +264,7 @@ static int xdg_config_parse_strv(
if (*end == ';') {
r = strv_strndup_unescape_and_push(unit, filename, line,
- &sv, &n_allocated, &n,
+ &sv, &n,
start, end);
if (r < 0)
return r;
@@ -276,7 +275,7 @@ static int xdg_config_parse_strv(
/* Handle the trailing entry after the last separator */
r = strv_strndup_unescape_and_push(unit, filename, line,
- &sv, &n_allocated, &n,
+ &sv, &n,
start, end);
if (r < 0)
return r;