]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: use _cleanup_
authorDavid Tardon <dtardon@redhat.com>
Tue, 28 Mar 2023 11:30:26 +0000 (13:30 +0200)
committerDavid Tardon <dtardon@redhat.com>
Tue, 11 Apr 2023 14:31:52 +0000 (16:31 +0200)
src/libsystemd/sd-bus/sd-bus.c

index cd9f33b5a95741084a3a9c40568a469c6ae8a40d..40dadf67a88f26a770a13fb7e50797515b6c8c52 100644 (file)
@@ -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(