[telepathy-mission-control/master] fd.o #20880: _mcd_object_ready: guard against premature freeing of object and double callback invocation

Simon McVittie simon.mcvittie at collabora.co.uk
Thu May 14 05:57:18 PDT 2009


* Ref the object across all the callback calls so it can't get finalized
  with callback invocations still pending
* Steal the ready-data from the object so re-entrant calls to
  _mcd_object_ready from inside a callback can't cause the callbacks to
  be invoked for a second time
---
 src/mcd-misc.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/mcd-misc.c b/src/mcd-misc.c
index 6acb9fc..33897e4 100644
--- a/src/mcd-misc.c
+++ b/src/mcd-misc.c
@@ -235,12 +235,18 @@ _mcd_object_ready (gpointer object, GQuark quark, const GError *error)
 {
     McdReadyData *rd;
 
-    rd = g_object_get_qdata ((GObject *)object, quark);
+    /* steal the qdata so the callbacks won't be invoked again, even if the
+     * object becomes ready or is finalized while still invoking them */
+    rd = g_object_steal_qdata ((GObject *)object, quark);
     if (!rd) return;
 
+    g_object_ref (object);
+
     mcd_object_invoke_ready_callbacks (rd, error);
     rd->strukt = NULL; /* so the callbacks won't be invoked again */
-    g_object_set_qdata ((GObject *)object, quark, NULL);
+    mcd_ready_data_free (rd);
+
+    g_object_unref (object);
 }
 
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list