From 01ae86990380f8c37d7609c41337bc95b0b7869d Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Thu, 22 Sep 2011 15:45:11 +0200 Subject: [PATCH] service: Don't iterate over changing sequence __connman_service_disconnect_all() should not iterate over the service_list directly because the ordering of the services can change when disconnecting a service (e.g. default service). The iterator might be invalid after a __connman_service_disconnect() call. It's better to iterate over a temporary list. --- src/service.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/service.c b/src/service.c index a6c764c..ae15470 100644 --- a/src/service.c +++ b/src/service.c @@ -4547,6 +4547,7 @@ int __connman_service_disconnect(struct connman_service *service) int __connman_service_disconnect_all(void) { GSequenceIter *iter; + GSList *services = NULL, *list; DBG(""); @@ -4555,15 +4556,23 @@ int __connman_service_disconnect_all(void) while (g_sequence_iter_is_end(iter) == FALSE) { struct connman_service *service = g_sequence_get(iter); + services = g_slist_prepend(services, service); + + iter = g_sequence_iter_next(iter); + } + + for (list = services; list != NULL; list = list->next) { + struct connman_service *service = list->data; + service->ignore = TRUE; set_reconnect_state(service, FALSE); __connman_service_disconnect(service); - - iter = g_sequence_iter_next(iter); } + g_slist_free(list); + return 0; } -- 2.7.4