From 90ab7e83ffae999eb811013e63cb7ef0afc012e4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 29 May 2014 10:50:45 +0200 Subject: [PATCH] platform: fix check_cache_items() to check items in two steps check_cache_items() iterated over all items and called refresh_object(). But refresh_object() might remove the current object from the cache, so this would break the iteration. Instead check the items in two steps. First find all the objects we care about and build a list of them. Then check them. Signed-off-by: Thomas Haller --- src/platform/nm-linux-platform.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 2adaf7e60f..a051d23570 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1278,12 +1278,20 @@ check_cache_items (NMPlatform *platform, struct nl_cache *cache, int ifindex) { auto_nl_cache struct nl_cache *cloned_cache = nl_cache_clone (cache); struct nl_object *object; + GPtrArray *objects_to_refresh = g_ptr_array_new_with_free_func ((GDestroyNotify) nl_object_put); + guint i; for (object = nl_cache_get_first (cloned_cache); object; object = nl_cache_get_next (object)) { - g_assert (nl_object_get_cache (object) == cloned_cache); - if (object_has_ifindex (object, ifindex)) - refresh_object (platform, object, TRUE, NM_PLATFORM_REASON_CACHE_CHECK); + if (object_has_ifindex (object, ifindex)) { + nl_object_get (object); + g_ptr_array_add (objects_to_refresh, object); + } } + + for (i = 0; i < objects_to_refresh->len; i++) + refresh_object (platform, object, TRUE, NM_PLATFORM_REASON_CACHE_CHECK); + + g_ptr_array_free (objects_to_refresh, TRUE); } static void