summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-11-26 02:54:11 +0100
committerLennart Poettering <lennart@poettering.net>2014-11-26 03:06:50 +0100
commit8aee3fc7eae2e60592bac838bc7268720e1d489c (patch)
treec53c845a3288260e40741732b24fc7903a119bd1 /src
parentfa7796e97b96160a4d78f72d113573770cec18f2 (diff)
sd-bus: don't clobber return values on failure in bus_kernel_open_bus_fd()
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index aa4b4240dc..6baa84c042 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -1514,20 +1514,29 @@ int bus_kernel_open_bus_fd(const char *bus, char **path) {
int fd;
size_t len;
+ assert(bus);
+
len = strlen("/sys/fs/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1;
if (path) {
- p = malloc(len);
+ p = new(char, len);
if (!p)
return -ENOMEM;
- *path = p;
} else
- p = alloca(len);
+ p = newa(char, len);
+
sprintf(p, "/sys/fs/kdbus/" UID_FMT "-%s/bus", getuid(), bus);
fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
- if (fd < 0)
+ if (fd < 0) {
+ if (path)
+ free(p);
+
return -errno;
+ }
+
+ if (path)
+ *path = p;
return fd;
}