summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2023-03-28 13:30:26 +0200
committerDavid Tardon <dtardon@redhat.com>2023-04-11 16:31:52 +0200
commitbd92527752e05b62b53424fd3848e6ed880e7b26 (patch)
tree9f99a7e73c40c3a2213cbf9299541458acc495e0 /src/libsystemd
parent04375b62139554c36fc8b919fd7df58add1041dc (diff)
downloadsystemd-bd92527752e05b62b53424fd3848e6ed880e7b26.tar.gz
sd-bus: use _cleanup_
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index cd9f33b5a9..40dadf67a8 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -3512,8 +3512,8 @@ static int bus_add_match_full(
struct bus_match_component *components = NULL;
size_t n_components = 0;
- sd_bus_slot *s = NULL;
- int r = 0;
+ _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *s = NULL;
+ int r;
assert_return(bus, -EINVAL);
assert_return(bus = bus_resolve(bus), -ENOPKG);
@@ -3524,13 +3524,11 @@ static int bus_add_match_full(
r = bus_match_parse(match, &components, &n_components);
if (r < 0)
- goto finish;
+ return r;
s = bus_slot_allocate(bus, !slot, BUS_MATCH_CALLBACK, sizeof(struct match_callback), userdata);
- if (!s) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!s)
+ return -ENOMEM;
s->match_callback.callback = callback;
s->match_callback.install_callback = install_callback;
@@ -3546,10 +3544,8 @@ static int bus_add_match_full(
/* We store the original match string, so that we can use it to remove the match again. */
s->match_callback.match_string = strdup(match);
- if (!s->match_callback.match_string) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!s->match_callback.match_string)
+ return -ENOMEM;
if (asynchronous) {
r = bus_add_match_internal_async(bus,
@@ -3559,7 +3555,7 @@ static int bus_add_match_full(
s);
if (r < 0)
- goto finish;
+ return r;
/* Make the slot of the match call floating now. We need the reference, but we don't
* want that this match pins the bus object, hence we first create it non-floating, but
@@ -3568,7 +3564,7 @@ static int bus_add_match_full(
} else
r = bus_add_match_internal(bus, s->match_callback.match_string, &s->match_callback.after);
if (r < 0)
- goto finish;
+ return r;
s->match_added = true;
}
@@ -3577,16 +3573,13 @@ static int bus_add_match_full(
bus->match_callbacks_modified = true;
r = bus_match_add(&bus->match_callbacks, components, n_components, &s->match_callback);
if (r < 0)
- goto finish;
+ return r;
if (slot)
*slot = s;
s = NULL;
-finish:
- sd_bus_slot_unref(s);
-
- return r;
+ return 0;
}
_public_ int sd_bus_add_match(