summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-05-14 14:09:03 +0900
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit29ba1025d320d5b22946410c09d88f2717eb0567 (patch)
treeb83d24c1f6c8e89d05e943e6bb9f0cf1e8098040
parent713e95b39f923b5b77315a4fe60650bdfcc81ec9 (diff)
sd-bus: use free_and_strdup()
-rw-r--r--src/libelogind/sd-bus/sd-bus.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c
index 22a7c99ea..2b72b6b56 100644
--- a/src/libelogind/sd-bus/sd-bus.c
+++ b/src/libelogind/sd-bus/sd-bus.c
@@ -265,19 +265,13 @@ _public_ int sd_bus_new(sd_bus **ret) {
}
_public_ int sd_bus_set_address(sd_bus *bus, const char *address) {
- char *a;
-
assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
assert_return(bus->state == BUS_UNSET, -EPERM);
assert_return(address, -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
- a = strdup(address);
- if (!a)
- return -ENOMEM;
-
- return free_and_replace(bus->address, a);
+ return free_and_strdup(&bus->address, address);
}
_public_ int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd) {
@@ -294,8 +288,8 @@ _public_ int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd) {
}
_public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) {
- _cleanup_free_ char *p = NULL;
- char **a;
+ _cleanup_strv_free_ char **a = NULL;
+ int r;
assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
@@ -304,17 +298,15 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[])
assert_return(!strv_isempty(argv), -EINVAL);
assert_return(!bus_pid_changed(bus), -ECHILD);
- p = strdup(path);
- if (!p)
- return -ENOMEM;
-
a = strv_copy(argv);
if (!a)
return -ENOMEM;
- free_and_replace(bus->exec_path, p);
- strv_free_and_replace(bus->exec_argv, a);
- return 0;
+ r = free_and_strdup(&bus->exec_path, path);
+ if (r < 0)
+ return r;
+
+ return strv_free_and_replace(bus->exec_argv, a);
}
_public_ int sd_bus_set_bus_client(sd_bus *bus, int b) {
@@ -538,7 +530,6 @@ void bus_set_state(sd_bus *bus, enum bus_state state) {
static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
- char *t;
sd_bus *bus;
int r;
@@ -558,11 +549,9 @@ static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *e
if (!service_name_is_valid(s) || s[0] != ':')
return -EBADMSG;
- t = strdup(s);
- if (!t)
- return -ENOMEM;
-
- free_and_replace(bus->unique_name, t);
+ r = free_and_strdup(&bus->unique_name, s);
+ if (r < 0)
+ return r;
if (bus->state == BUS_HELLO) {
bus_set_state(bus, BUS_RUNNING);