From: David Tardon Date: Tue, 28 Mar 2023 11:30:26 +0000 (+0200) Subject: sd-bus: use _cleanup_ X-Git-Tag: v254-rc1~752^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd92527752e05b62b53424fd3848e6ed880e7b26;p=thirdparty%2Fsystemd.git sd-bus: use _cleanup_ --- diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index cd9f33b5a95..40dadf67a88 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(