]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl-list-units: fix memleak on error
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Feb 2023 07:38:18 +0000 (16:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Feb 2023 06:13:05 +0000 (15:13 +0900)
src/systemctl/systemctl-list-units.c

index 8e537300782be546eaf687bb56ca46cadde0ff7c..a0e0a79ad4971cacef7d5e837fbefc251d538951 100644 (file)
@@ -27,7 +27,7 @@ static int get_unit_list_recursive(
 
         _cleanup_free_ UnitInfo *unit_infos = NULL;
         _cleanup_(message_set_freep) Set *replies = NULL;
-        sd_bus_message *reply;
+        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         int c, r;
 
         assert(bus);
@@ -44,10 +44,9 @@ static int get_unit_list_recursive(
                 return c;
 
         r = set_put(replies, reply);
-        if (r < 0) {
-                sd_bus_message_unref(reply);
+        if (r < 0)
                 return log_oom();
-        }
+        TAKE_PTR(reply);
 
         if (arg_recursive) {
                 _cleanup_strv_free_ char **machines = NULL;
@@ -73,10 +72,9 @@ static int get_unit_list_recursive(
                         c = k;
 
                         r = set_put(replies, reply);
-                        if (r < 0) {
-                                sd_bus_message_unref(reply);
+                        if (r < 0)
                                 return log_oom();
-                        }
+                        TAKE_PTR(reply);
                 }
 
                 *ret_machines = TAKE_PTR(machines);