From 08834f9c2f5ecee4044a76d4e2374662d7c40e74 Mon Sep 17 00:00:00 2001 From: Alfonso Sanchez-Beato Date: Mon, 2 Nov 2015 17:48:41 +0100 Subject: gril: Fix access to notify callbacks Entries to the table of notification callbacks can be added by the callbacks while being called. This caused a glib error as gril was using an iterator to the hash table while the table was being modified. Fixed by avoiding the unnecesary loop. --- gril/gril.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/gril/gril.c b/gril/gril.c index ead82062..d279c449 100644 --- a/gril/gril.c +++ b/gril/gril.c @@ -420,48 +420,36 @@ static gboolean node_check_destroyed(struct ril_notify_node *node, static void handle_unsol_req(struct ril_s *p, struct ril_msg *message) { - GHashTableIter iter; struct ril_notify *notify; - int req_key; - gpointer key, value; - GList *list_item; - struct ril_notify_node *node; - gboolean found = FALSE; if (p->notify_list == NULL) return; p->in_notify = TRUE; - g_hash_table_iter_init(&iter, p->notify_list); + notify = g_hash_table_lookup(p->notify_list, &message->req); + if (notify != NULL) { + GSList *list_item; - while (g_hash_table_iter_next(&iter, &key, &value)) { - req_key = *((int *)key); - notify = value; - - if (req_key != message->req) - continue; + for (list_item = notify->nodes; list_item; + list_item = g_slist_next(list_item)) { + struct ril_notify_node *node = list_item->data; - list_item = (GList *) notify->nodes; - - while (list_item != NULL) { - node = list_item->data; + if (node->destroyed) + continue; node->callback(message, node->user_data); - found = TRUE; - list_item = (GList *) g_slist_next(list_item); } - } - - /* Only log events not being listended for... */ - if (!found) + } else { + /* Only log events not being listended for... */ DBG("RIL Event slot %d: %s\n", p->slot, unsol_request_to_string(p, message->req)); + } p->in_notify = FALSE; /* Now destroy nodes possibly removed by callbacks */ - if (found) + if (notify != NULL) ril_unregister_all(p, FALSE, node_check_destroyed, GUINT_TO_POINTER(TRUE)); } -- cgit v1.2.3