[folks] Tidy up signal disconnections in IndividualAggregator



commit e5c020e4e871e328fc401b4dfd2a9935a9fe6b9b
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Fri Apr 22 22:47:49 2011 +0100

    Tidy up signal disconnections in IndividualAggregator
    
    Closes: bgo#645186

 NEWS                             |    1 +
 folks/individual-aggregator.vala |   26 ++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5763e78..4c8295d 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Bugs fixed:
 * Bug 645684 â?? Implement Iterator on LinkedHashSet
 * Bug 640092 â?? Folks should minimize use of GLib.List (including its public API)
 * Bug 648161 â?? Add GObject Introspection Support
+* Bug 645186 â?? Make sure all connect() calls have appropriate disconnect() calls
 
 API changes:
 * LinkedHashSet.list_iterator() is now disallowed (causes an assertion failure)
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index f0e0d54..154311f 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -198,6 +198,13 @@ public class Folks.IndividualAggregator : Object
           this._backend_available_cb);
     }
 
+  ~IndividualAggregator ()
+    {
+      this._backend_store.backend_available.disconnect (
+          this._backend_available_cb);
+      this._backend_store = null;
+    }
+
   /**
    * Prepare the IndividualAggregator for use.
    *
@@ -383,6 +390,18 @@ public class Folks.IndividualAggregator : Object
       return type_id + ":" + id;
     }
 
+  private void _connect_to_individual (Individual individual)
+    {
+      individual.removed.connect (this._individual_removed_cb);
+      this.individuals.set (individual.id, individual);
+    }
+
+  private void _disconnect_from_individual (Individual individual)
+    {
+      this.individuals.unset (individual.id);
+      individual.removed.disconnect (this._individual_removed_cb);
+    }
+
   private void _add_personas (Set<Persona> added,
       ref HashSet<Individual> added_individuals,
       ref HashMap<Individual, Individual> replaced_individuals,
@@ -586,9 +605,8 @@ public class Folks.IndividualAggregator : Object
       foreach (var i in almost_added_individuals)
         {
           /* Add the new Individual to the aggregator */
-          i.removed.connect (this._individual_removed_cb);
           added_individuals.add (i);
-          this.individuals.set (i.id, i);
+          this._connect_to_individual (i);
         }
     }
 
@@ -704,7 +722,7 @@ public class Folks.IndividualAggregator : Object
           if (user == individual)
             user = null;
 
-          this.individuals.unset (individual.id);
+          this._disconnect_from_individual (individual);
           individual.personas = null;
         }
 
@@ -800,7 +818,7 @@ public class Folks.IndividualAggregator : Object
               individuals, null, null, 0);
         }
 
-      this.individuals.unset (i.id);
+      this._disconnect_from_individual (i);
     }
 
   /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]