diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index db34eb14c9..b0c46a7464 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -201,7 +201,7 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) /* Extract gateway from default route */ old_gateway = priv->gateway; - for (i = 0; i < priv->routes->len; i++) { + for (i = 0; i < priv->routes->len; ) { const NMPlatformIP4Route *route = &g_array_index (priv->routes, NMPlatformIP4Route, i); if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) { @@ -211,9 +211,10 @@ nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf) } has_gateway = TRUE; /* Remove the default route from the list */ - g_array_remove_index (priv->routes, i); - i--; + g_array_remove_index_fast (priv->routes, i); + continue; } + i++; } /* If there is a host route to the gateway, ignore that route. It is diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index cbad11ad01..4d1718fd52 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -313,7 +313,7 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co /* Extract gateway from default route */ old_gateway = priv->gateway; - for (i = 0; i < priv->routes->len; i++) { + for (i = 0; i < priv->routes->len; ) { const NMPlatformIP6Route *route = &g_array_index (priv->routes, NMPlatformIP6Route, i); if (NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route)) { @@ -323,9 +323,10 @@ nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6Co } has_gateway = TRUE; /* Remove the default route from the list */ - g_array_remove_index (priv->routes, i); - i--; + g_array_remove_index_fast (priv->routes, i); + continue; } + i++; } /* If there is a host route to the gateway, ignore that route. It is