[folks] When removing, use a local copy of the personas



commit 3832a5d8f6ec6da40c3770168a7bce1005fc1bc0
Author: Sjoerd Simons <sjoerd simons collabora co uk>
Date:   Wed Mar 23 09:33:43 2011 +0000

    When removing, use a local copy of the personas
    
    Removing personas from folks will change our individuals persona list,
    so we need to make a copy to be able to safely iterate it.

 NEWS                             |    1 +
 folks/individual-aggregator.vala |    9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4e5e220..85e56e4 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Bugs fixed:
 * Bug 644527 - Add a Tracker backend
 * Bug 645430 - folks-inspect: Use LinkedHashSet to access im-addresses
 * Bug 645411 - folks-import segfaults on startup
+* Crasher when removing Personas
 
 Overview of changes from libfolks 0.3.6 to libfolks 0.4.0
 =========================================================
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index f3da07b..6c0bb78 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -794,9 +794,14 @@ public class Folks.IndividualAggregator : Object
   public async void remove_individual (Individual individual) throws GLib.Error
     {
       /* We have to iterate manually since using foreach() requires a sync
-       * lambda function, meaning we can't yield on the remove_persona() call */
+       * lambda function, meaning we can't yield on the remove_persona() call.
+       *
+       * Furthermore, removing personas changes the persona list so we need to
+       * make a copy first */
+      var personas = individual.personas.copy ();
       unowned GLib.List<unowned Persona> i;
-      for (i = individual.personas; i != null; i = i.next)
+
+      for (i = personas; i != null; i = i.next)
         {
           var persona = (Persona) i.data;
           yield persona.store.remove_persona (persona);



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