]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device-enumerator: use _cleanup_free_ attribute for safety 24609/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 11:55:45 +0000 (20:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 12:16:37 +0000 (21:16 +0900)
No functional changes, just improve readability.

Suggested by https://github.com/systemd/systemd/pull/24601#discussion_r966883459.

src/libsystemd/sd-device/device-enumerator.c

index 5afe9f348f095d517be789feec3a4a8059dcb2ed..a583a37dab22d02d8d98a221a8eb157aa9da981c 100644 (file)
@@ -935,13 +935,17 @@ static int enumerator_scan_devices_children(sd_device_enumerator *enumerator) {
                         r = k;
         }
 
-        for (char *p; (p = set_steal_first(stack)); free(p)) {
+        for (;;) {
+                _cleanup_free_ char *p = NULL;
+
+                p = set_steal_first(stack);
+                if (!p)
+                        return r;
+
                 k = parent_crawl_children(enumerator, p, &stack);
                 if (k < 0)
                         r = k;
         }
-
-        return r;
 }
 
 static int enumerator_scan_devices_all(sd_device_enumerator *enumerator) {