summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-control.c
diff options
context:
space:
mode:
authorLukasz Skalski <l.skalski@samsung.com>2014-10-16 19:01:12 +0200
committerLennart Poettering <lennart@poettering.net>2014-10-20 20:09:05 +0200
commit659b937e670a5cb423a274b97b1eb60abd7d218f (patch)
treec83b8d5ac1b4a7a5c871b88d42ef57eec36c6bae /src/libsystemd/sd-bus/bus-control.c
parentcd4c6fb12598435fe24431f1dd616f9582f0e3bd (diff)
kdbus: free returned buffer when the memory is no longer needed
Diffstat (limited to 'src/libsystemd/sd-bus/bus-control.c')
-rw-r--r--src/libsystemd/sd-bus/bus-control.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index cf733a663c..fa321d5315 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -265,12 +265,14 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->owner_id != previous_id) {
char *n;
- if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
- return -ENOMEM;
+ if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
r = strv_consume(x, n);
if (r < 0)
- return r;
+ goto fail;
previous_id = name->owner_id;
}
@@ -281,16 +283,18 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
if (entry_name && service_name_is_valid(entry_name)) {
r = strv_extend(x, entry_name);
- if (r < 0)
- return -ENOMEM;
+ if (r < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
}
}
- r = kernel_cmd_free(bus, cmd.offset);
- if (r < 0)
- return r;
+ r = 0;
- return 0;
+fail:
+ kernel_cmd_free(bus, cmd.offset);
+ return r;
}
static int bus_list_names_kernel(sd_bus *bus, char ***acquired, char ***activatable) {
@@ -428,16 +432,25 @@ static int bus_get_owner_kdbus(
conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
/* Non-activated names are considered not available */
- if (conn_info->flags & KDBUS_HELLO_ACTIVATOR)
- return name[0] == ':' ? -ENXIO : -ESRCH;
+ if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
+ if (name[0] == ':')
+ r = -ENXIO;
+ else
+ r = -ESRCH;
+ goto fail;
+ }
c = bus_creds_new();
- if (!c)
- return -ENOMEM;
+ if (!c) {
+ r = -ENOMEM;
+ goto fail;
+ }
if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
- if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
- return -ENOMEM;
+ if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
}