summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-11-16 13:24:13 +0100
committerBastien Nocera <hadess@hadess.net>2018-11-16 14:34:58 +0100
commit0711247c17934a2abfd170f29a043965374979a6 (patch)
treeaeb76d082fc425593ddddf485e860b43ece7bfde
parent915e3f8b53421efabb1197bffd92cf306659f5f3 (diff)
downloadgrilo-0711247c17934a2abfd170f29a043965374979a6.tar.gz
registry: Fix g_hash_table_iter_next() warning
As we loop through the sources as listed in the hash table, there's a good chance that the hash table will be modified as sources are added or removed. But as we shouldn't be modifying the hash table while it's being iterated over, the code throws a warning, and will exit the loop. Warning: g_hash_table_iter_next: assertion 'ri->version == ri->hash_table->version' failed Solve this by getting a list of all the sources in advance.
-rw-r--r--src/grl-registry.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/grl-registry.c b/src/grl-registry.c
index 4124ddd..c03be54 100644
--- a/src/grl-registry.c
+++ b/src/grl-registry.c
@@ -220,17 +220,22 @@ network_changed_cb (GObject *gobject,
{
GNetworkConnectivity connectivity;
gboolean network_available;
- GHashTableIter iter;
GrlSource *current_source;
+ GList *sources, *l;
GRL_DEBUG ("Network availability changed");
get_connectivity (registry, &connectivity, &network_available);
+ sources = g_hash_table_get_values (registry->priv->sources);
+ if (!sources)
+ return;
+
if (!network_available) {
- g_hash_table_iter_init (&iter, registry->priv->sources);
+ for (l = sources; l != NULL; l = l->next) {
+ const char **tags;
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &current_source)) {
- const char **tags = grl_source_get_tags (current_source);
+ current_source = l->data;
+ tags = grl_source_get_tags (current_source);
if (!tags)
continue;
@@ -245,9 +250,11 @@ network_changed_cb (GObject *gobject,
}
}
} else {
- g_hash_table_iter_init (&iter, registry->priv->sources);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &current_source)) {
- const char **tags = grl_source_get_tags (current_source);
+ for (l = sources; l != NULL; l = l->next) {
+ const char **tags;
+
+ current_source = l->data;
+ tags = grl_source_get_tags (current_source);
if (!tags)
continue;
@@ -279,6 +286,8 @@ network_changed_cb (GObject *gobject,
}
}
}
+
+ g_list_free (sources);
}
static void