From: Yu Watanabe Date: Wed, 22 Feb 2023 07:38:18 +0000 (+0900) Subject: systemctl-list-units: fix memleak on error X-Git-Tag: v254-rc1~1173^2~5 X-Git-Url: http://git-history.diyao.me/?a=commitdiff_plain;h=eef96911e1f7ec59acdd01e67663a0f3046059db;p=systemd%2F.git systemctl-list-units: fix memleak on error --- diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c index 8e53730078..a0e0a79ad4 100644 --- a/src/systemctl/systemctl-list-units.c +++ b/src/systemctl/systemctl-list-units.c @@ -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);