diff options
author | David Tardon <dtardon@redhat.com> | 2018-05-11 18:43:40 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-12 18:29:41 +0200 |
commit | 95f14a3e21b4d99383f37da9dc66021cf5ac22c2 (patch) | |
tree | 1bd855cd03c90d9f041900098e060465220fea2c | |
parent | fee09fb7ac5d56a644445c528ca501d44e701755 (diff) | |
download | systemd-95f14a3e21b4d99383f37da9dc66021cf5ac22c2.tar.gz |
core: use automatic cleanup more
-rw-r--r-- | src/core/device.c | 12 | ||||
-rw-r--r-- | src/core/swap.c | 10 | ||||
-rw-r--r-- | src/core/unit.c | 12 |
3 files changed, 11 insertions, 23 deletions
diff --git a/src/core/device.c b/src/core/device.c index 565410fd36..0bf329c3d2 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -704,7 +704,7 @@ static Unit *device_following(Unit *u) { static int device_following_set(Unit *u, Set **_set) { Device *d = DEVICE(u), *other; - Set *set; + _cleanup_(set_freep) Set *set = NULL; int r; assert(d); @@ -722,21 +722,17 @@ static int device_following_set(Unit *u, Set **_set) { LIST_FOREACH_AFTER(same_sysfs, other, d) { r = set_put(set, other); if (r < 0) - goto fail; + return r; } LIST_FOREACH_BEFORE(same_sysfs, other, d) { r = set_put(set, other); if (r < 0) - goto fail; + return r; } - *_set = set; + *_set = TAKE_PTR(set); return 1; - -fail: - set_free(set); - return r; } static void device_shutdown(Manager *m) { diff --git a/src/core/swap.c b/src/core/swap.c index 4d9f4df6ed..965d96f4da 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1240,7 +1240,7 @@ static Unit *swap_following(Unit *u) { static int swap_following_set(Unit *u, Set **_set) { Swap *s = SWAP(u), *other; - Set *set; + _cleanup_(set_freep) Set *set = NULL; int r; assert(s); @@ -1258,15 +1258,11 @@ static int swap_following_set(Unit *u, Set **_set) { LIST_FOREACH_OTHERS(same_devnode, other, s) { r = set_put(set, other); if (r < 0) - goto fail; + return r; } - *_set = set; + *_set = TAKE_PTR(set); return 1; - -fail: - set_free(set); - return r; } static void swap_shutdown(Manager *m) { diff --git a/src/core/unit.c b/src/core/unit.c index 09ed43a104..5b7beca369 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3815,7 +3815,7 @@ int unit_kill(Unit *u, KillWho w, int signo, sd_bus_error *error) { } static Set *unit_pid_set(pid_t main_pid, pid_t control_pid) { - Set *pid_set; + _cleanup_(set_freep) Set *pid_set = NULL; int r; pid_set = set_new(NULL); @@ -3826,20 +3826,16 @@ static Set *unit_pid_set(pid_t main_pid, pid_t control_pid) { if (main_pid > 0) { r = set_put(pid_set, PID_TO_PTR(main_pid)); if (r < 0) - goto fail; + return NULL; } if (control_pid > 0) { r = set_put(pid_set, PID_TO_PTR(control_pid)); if (r < 0) - goto fail; + return NULL; } - return pid_set; - -fail: - set_free(pid_set); - return NULL; + return TAKE_PTR(pid_set); } int unit_kill_common( |