diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-11-27 02:28:23 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-27 22:02:12 +0100 |
commit | 50c4521675e94ade38b8af9e3b0f7fd2f300b6f4 (patch) | |
tree | 30e2586117fa037cc4dabffa934c612319bf1708 /src/libsystemd/sd-bus/bus-kernel.c | |
parent | 7fa934b0d35492b300b79848f4822ffc40eee21f (diff) |
sd-bus: optimize how we generate the well-known-names lists in messages from kdbus
Diffstat (limited to 'src/libsystemd/sd-bus/bus-kernel.c')
-rw-r--r-- | src/libsystemd/sd-bus/bus-kernel.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index ef157d69f2..1276cd841a 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -660,9 +660,23 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { } if (bus->creds_mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) { - r = strv_extend(&m->creds.well_known_names, d->name.name); - if (r < 0) + char **wkn; + size_t n; + + /* We just extend the array here, but + * do not allocate the strings inside + * of it, instead we just point to our + * buffer directly. */ + n = strv_length(m->creds.well_known_names); + wkn = realloc(m->creds.well_known_names, (n + 2) * sizeof(char*)); + if (!wkn) { + r = -ENOMEM; goto fail; + } + + wkn[n] = d->name.name; + wkn[n+1] = NULL; + m->creds.well_known_names = wkn; m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES; } |