diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-02-09 16:21:51 +0900 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-05-30 07:58:49 +0200 |
commit | f89f4407ce482c15273adee1668e631d437fc601 (patch) | |
tree | f9a168d64b20f88256251b929ace4bcdcd6fc239 /src/libelogind/sd-bus/sd-bus.c | |
parent | 915d7180e74ae5a57fe19fa53fc00974ed417c5e (diff) |
sd-bus: use free_and_replace()
Diffstat (limited to 'src/libelogind/sd-bus/sd-bus.c')
-rw-r--r-- | src/libelogind/sd-bus/sd-bus.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/libelogind/sd-bus/sd-bus.c b/src/libelogind/sd-bus/sd-bus.c index f11cdce85..96d0a59f1 100644 --- a/src/libelogind/sd-bus/sd-bus.c +++ b/src/libelogind/sd-bus/sd-bus.c @@ -291,8 +291,7 @@ _public_ int sd_bus_set_address(sd_bus *bus, const char *address) { if (!a) return -ENOMEM; - free(bus->address); - bus->address = a; + free_and_replace(bus->address, a); return 0; } @@ -330,10 +329,9 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) return -ENOMEM; } - free(bus->exec_path); - strv_free(bus->exec_argv); + free_and_replace(bus->exec_path, p); - bus->exec_path = p; + strv_free(bus->exec_argv); bus->exec_argv = a; return 0; @@ -657,8 +655,8 @@ int bus_start_running(sd_bus *bus) { static int parse_address_key(const char **p, const char *key, char **value) { size_t l, n = 0, allocated = 0; + _cleanup_free_ char *r = NULL; const char *a; - char *r = NULL; assert(p); assert(*p); @@ -686,16 +684,12 @@ static int parse_address_key(const char **p, const char *key, char **value) { int x, y; x = unhexchar(a[1]); - if (x < 0) { - free(r); + if (x < 0) return x; - } y = unhexchar(a[2]); - if (y < 0) { - free(r); + if (y < 0) return y; - } c = (char) ((x << 4) | y); a += 3; @@ -722,8 +716,7 @@ static int parse_address_key(const char **p, const char *key, char **value) { *p = a; - free(*value); - *value = r; + free_and_replace(*value, r); return 1; } |