From: Yu Watanabe Date: Fri, 19 Jan 2024 11:04:01 +0000 (+0900) Subject: local-addresses: fix memleak of 'multipath_routes' X-Git-Tag: v256-rc1~1074^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4019bec852a3e16a4a20008995d0c5f9265a04a7;p=thirdparty%2Fsystemd.git local-addresses: fix memleak of 'multipath_routes' Also reduces scopes of some variables. --- diff --git a/src/shared/local-addresses.c b/src/shared/local-addresses.c index c8feb58407e..6fc54b7baba 100644 --- a/src/shared/local-addresses.c +++ b/src/shared/local-addresses.c @@ -252,15 +252,10 @@ int local_gateways( return r; for (sd_netlink_message *m = reply; m; m = sd_netlink_message_next(m)) { - _cleanup_ordered_set_free_free_ OrderedSet *multipath_routes = NULL; - _cleanup_free_ void *rta_multipath = NULL; - union in_addr_union gateway; uint16_t type; unsigned char dst_len, src_len, table; uint32_t ifi = 0, priority = 0; - size_t rta_len; int family; - RouteVia via; r = sd_netlink_message_get_errno(m); if (r < 0) @@ -312,6 +307,7 @@ int local_gateways( if (ifindex > 0 && (int) ifi != ifindex) continue; + union in_addr_union gateway; r = netlink_message_read_in_addr_union(m, RTA_GATEWAY, family, &gateway); if (r < 0 && r != -ENODATA) return r; @@ -331,6 +327,7 @@ int local_gateways( if (family != AF_INET) continue; + RouteVia via; r = sd_netlink_message_read(m, RTA_VIA, sizeof(via), &via); if (r < 0 && r != -ENODATA) return r; @@ -346,10 +343,13 @@ int local_gateways( } } + size_t rta_len; + _cleanup_free_ void *rta_multipath = NULL; r = sd_netlink_message_read_data(m, RTA_MULTIPATH, &rta_len, &rta_multipath); if (r < 0 && r != -ENODATA) return r; if (r >= 0) { + _cleanup_ordered_set_free_free_ OrderedSet *multipath_routes = NULL; MultipathRoute *mr; r = rtattr_read_nexthop(rta_multipath, rta_len, family, &multipath_routes);