summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-bus/bus-creds.c
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/libsystemd/sd-bus/bus-creds.c
parentalloc-util: add MALLOC_ELEMENTSOF() helper (diff)
downloadsystemd-319a4f4bc46b230fc660321e99aaac1bc449deea.tar.xz
systemd-319a4f4bc46b230fc660321e99aaac1bc449deea.zip
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/libsystemd/sd-bus/bus-creds.c')
-rw-r--r--src/libsystemd/sd-bus/bus-creds.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 5e748fdb46..4468b45dd1 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -882,8 +882,6 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (missing & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
p = startswith(line, "Groups:");
if (p) {
- size_t allocated = 0;
-
for (;;) {
unsigned long g;
int n = 0;
@@ -895,7 +893,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (sscanf(p, "%lu%n", &g, &n) != 1)
return -EIO;
- if (!GREEDY_REALLOC(c->supplementary_gids, allocated, c->n_supplementary_gids+1))
+ if (!GREEDY_REALLOC(c->supplementary_gids, c->n_supplementary_gids+1))
return -ENOMEM;
c->supplementary_gids[c->n_supplementary_gids++] = (gid_t) g;