[folks] Copy new PhoneDetails for individuals, don't hold stale pointers.



commit 312103b5268bab3030378032d797f1dcf0fa7168
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date:   Wed Mar 16 22:04:50 2011 +0000

    Copy new PhoneDetails for individuals, don't hold stale pointers.
    
    Fixed bgo#644968 - _update_phone_numbers () needs to create copies
    of each List<FieldDetails>

 NEWS                  |    2 ++
 folks/individual.vala |   13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 432244f..77b4e6a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
 =========================================================
 
 Bugs fixed:
+* Bug 644968 - _update_phone_numbers() needs to create copies
+  of each List<FieldDetails>
 * Bug 644966 - _update_emails () needs to create copies of each
   List<FieldDetails>
 
diff --git a/folks/individual.vala b/folks/individual.vala
index a81036f..fca2136 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -1104,6 +1104,8 @@ public class Folks.Individual : Object,
       var phone_numbers_set =
           new HashTable<unowned string, unowned FieldDetails> (
               str_hash, str_equal);
+      var phones = new GLib.List<FieldDetails> ();
+
       foreach (var persona in this._persona_list)
         {
           var phone_details = persona as PhoneDetails;
@@ -1118,11 +1120,18 @@ public class Folks.Individual : Object,
                   if (existing != null)
                     existing.extend_parameters (fd.parameters);
                   else
-                    phone_numbers_set.insert (fd.value, fd);
+                    {
+                      var new_fd = new FieldDetails (fd.value);
+                      new_fd.extend_parameters (fd.parameters);
+                      phone_numbers_set.insert (fd.value, new_fd);
+                      phones.prepend ((owned) new_fd);
+                    }
                 }
             }
         }
-      this._phone_numbers = phone_numbers_set.get_values ();
+      /* Set the private member directly to avoid iterating this list again */
+      phones.reverse ();
+      this._phone_numbers = (owned) phones;
 
       this.notify_property ("phone-numbers");
     }



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