diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-02-09 16:21:29 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-02-09 16:21:29 +0900 |
commit | b4ca3f45dc5742ad76e8feebd363c490f92b804f (patch) | |
tree | 2ea3ee9ec1151e1e756558328bd68f9bc98d0adf /src/libsystemd/sd-bus/sd-bus.c | |
parent | 996def17f99bb3f41f82032860dfcb98ff19c3ae (diff) | |
download | systemd-b4ca3f45dc5742ad76e8feebd363c490f92b804f.tar.gz |
sd-bus: avoid potential memory leaks
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 7e7ebb27a7..58a08d5a4a 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -556,6 +556,7 @@ 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; @@ -575,10 +576,12 @@ static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *e if (!service_name_is_valid(s) || s[0] != ':') return -EBADMSG; - bus->unique_name = strdup(s); - if (!bus->unique_name) + t = strdup(s); + if (!t) return -ENOMEM; + free_and_replace(bus->unique_name, t); + if (bus->state == BUS_HELLO) { bus_set_state(bus, BUS_RUNNING); @@ -1377,7 +1380,7 @@ fail: int bus_set_address_system_remote(sd_bus *b, const char *host) { _cleanup_free_ char *e = NULL; - char *m = NULL, *c = NULL; + char *m = NULL, *c = NULL, *a; assert(b); assert(host); @@ -1408,10 +1411,12 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) { return -ENOMEM; } - b->address = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=systemd-stdio-bridge", c); - if (!b->address) + a = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=systemd-stdio-bridge", c); + if (!a) return -ENOMEM; + free_and_replace(b->address, a); + return 0; } @@ -1449,6 +1454,7 @@ fail: int bus_set_address_system_machine(sd_bus *b, const char *machine) { _cleanup_free_ char *e = NULL; + char *a; assert(b); assert(machine); @@ -1457,10 +1463,12 @@ int bus_set_address_system_machine(sd_bus *b, const char *machine) { if (!e) return -ENOMEM; - b->address = strjoin("x-machine-unix:machine=", e); - if (!b->address) + a = strjoin("x-machine-unix:machine=", e); + if (!a) return -ENOMEM; + free_and_replace(b->address, a); + return 0; } |