[folks] Persona: make sure to NULL-ify the individual when it's destroyed



commit 11b837ad8c3474da9b7048be9401269522d569d5
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Mar 19 14:21:37 2012 +0100

    Persona: make sure to NULL-ify the individual when it's destroyed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672381

 folks/persona.vala |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/folks/persona.vala b/folks/persona.vala
index 75970fd..3f7735f 100644
--- a/folks/persona.vala
+++ b/folks/persona.vala
@@ -137,6 +137,14 @@ public abstract class Folks.Persona : Object
    */
   public weak PersonaStore store { get; construct; }
 
+  private void _individual_weak_notify_cb (Object obj)
+    {
+      debug ("Individual %p has been destroyed; resetting the Individual of %s",
+          obj, this.iid);
+      this._individual = null;
+      this.notify_property ("individual");
+    }
+
   /**
    * The { link Individual} which contains this Persona.
    *
@@ -160,6 +168,16 @@ public abstract class Folks.Persona : Object
         {
           assert (value == null || ((!) value).personas.contains (this));
 
+          if (this._individual != null)
+            {
+              this._individual.weak_unref (this._individual_weak_notify_cb);
+            }
+
+          if (value != null)
+            {
+              value.weak_ref (this._individual_weak_notify_cb);
+            }
+
           this._individual = value;
         }
     }
@@ -323,4 +341,9 @@ public abstract class Folks.Persona : Object
           ((string) ((char*) uid + backend_name_length +
               persona_store_id_length + 2)));
     }
+
+  ~Persona ()
+    {
+      this.individual = null;
+    }
 }



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