[telepathy-gabble/master] re-implement gabble_search_manager_close_all using gabble_search_channel_close

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Aug 24 08:13:05 PDT 2009


This is cleaner than assume we are owning the only reference on the
channel and rely on the side effect than disposing the channel will
close it.
---
 src/search-manager.c |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/search-manager.c b/src/search-manager.c
index 18d3dd9..523b829 100644
--- a/src/search-manager.c
+++ b/src/search-manager.c
@@ -84,17 +84,26 @@ gabble_search_manager_init (GabbleSearchManager *self)
 static void
 gabble_search_manager_close_all (GabbleSearchManager *self)
 {
-  /* Use a temporary variable because we don't want search_channel_closed_cb to
-   * remove the channel from the hash table a second time
-   */
-  if (self->priv->channels != NULL)
+  GList *chans, *l;
+
+  if (self->priv->channels == NULL)
+    return;
+
+  DEBUG ("closing channels");
+
+  /* We can't use a GHashTableIter as closing the channel while remove it from
+   * the hash table and we can't modify a hash table while iterating on it. */
+  chans = g_hash_table_get_keys (self->priv->channels);
+  for (l = chans; l != NULL; l = g_list_next (l))
     {
-      GHashTable *tmp = self->priv->channels;
+      GabbleSearchChannel *chan = GABBLE_SEARCH_CHANNEL (l->data);
 
-      DEBUG ("closing channels");
-      self->priv->channels = NULL;
-      g_hash_table_destroy (tmp);
+      gabble_search_channel_close (chan);
     }
+
+  g_hash_table_destroy (self->priv->channels);
+  self->priv->channels = NULL;
+  g_list_free (chans);
 }
 
 static void
-- 
1.5.6.5




More information about the telepathy-commits mailing list