Tidy up signal disconnections in IndividualAggregator
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 22 Apr 2011 21:47:49 +0000 (22:47 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Tue, 26 Apr 2011 20:52:30 +0000 (21:52 +0100)
Closes: bgo#645186

NEWS
folks/individual-aggregator.vala

diff --git a/NEWS b/NEWS
index 5763e78..4c8295d 100644 (file)
--- 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)
index f0e0d54..154311f 100644 (file)
@@ -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);
     }
 
   /**