]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/ndisc: unref Route objects that depend on the nexthop
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Nov 2024 16:57:44 +0000 (01:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 02:21:14 +0000 (11:21 +0900)
No functional change, as when this function is called, the set will be
freed and contained Route objects will be unref()ed anyway soon later
by nexthop_detach() -> nexthop_free().
Even though, when the routes are forgotten from the Manager, then it is
not necessary to keep them by the nexthop. Let's unref earlier.

src/network/networkd-nexthop.c

index eb557e580ee17a2aad6f68f0b5ea49be279c50c1..8e101ad779b5b2ed186b6a515c8d551a5ab19a03 100644 (file)
@@ -493,8 +493,11 @@ static void nexthop_forget_dependents(NextHop *nexthop, Manager *manager) {
         /* If a nexthop is removed, the kernel silently removes routes that depend on the removed nexthop.
          * Let's forget them. */
 
-        Route *route;
-        SET_FOREACH(route, nexthop->routes) {
+        for (;;) {
+                _cleanup_(route_unrefp) Route *route = set_steal_first(nexthop->routes);
+                if (!route)
+                        break;
+
                 Request *req;
                 if (route_get_request(manager, route, &req) >= 0)
                         route_enter_removed(req->userdata);
@@ -503,6 +506,8 @@ static void nexthop_forget_dependents(NextHop *nexthop, Manager *manager) {
                 log_route_debug(route, "Forgetting silently removed", manager);
                 route_detach(route);
         }
+
+        nexthop->routes = set_free(nexthop->routes);
 }
 
 static int nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, RemoveRequest *rreq) {