summaryrefslogtreecommitdiffstats
path: root/gril/gril.c
diff options
context:
space:
mode:
authorAlfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>2015-11-02 17:48:41 +0100
committerDenis Kenzior <denkenz@gmail.com>2015-11-02 12:40:50 -0600
commit08834f9c2f5ecee4044a76d4e2374662d7c40e74 (patch)
treee0a2556f41fbab2a2e9334a98ee6bf05efc1b7eb /gril/gril.c
parent2113b0a5ed97b0e9805efac954dce4acd78fc77d (diff)
downloadofono-08834f9c2f5ecee4044a76d4e2374662d7c40e74.tar.bz2
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.
Diffstat (limited to 'gril/gril.c')
-rw-r--r--gril/gril.c36
1 files 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));
}