[gjs/gnome-3-28] object: Only weak unref if GObject is still alive



commit 8d85400b7251ef8f299b0262b58d2fa035d6b7a2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Apr 19 22:27:55 2018 -0300

    object: Only weak unref if GObject is still alive
    
    The function disassociate_js_gobject() is currently unconditionally
    removing the weak reference of the wrapped GObject. This is because
    we were previously assuming that there was always a toggle ref, and
    so we would never reach this code path after the wrapped GObject was
    destroyed.
    
    Turns out, with commit 0cc23474f815 it is now a regular case to call
    this function after the GObject is finalized. When that happens, it
    will reach wrapped_gobj_dispose_notify() and the wrapped GObject will
    be marked as finalized. disassociate_js_gobject(), however, will try
    to weak unref it, without checking if the GObject was finalized already.
    
    This commit fix that by simply checking if the wrapped GObject was
    finalized before trying to weak unref it.
    
    (cherry picked from commit 8d50e2b401236a380bb16301308b331413217a2d)

 gi/object.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 4b2ec109..98b83a76 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1413,7 +1413,8 @@ disassociate_js_gobject(GObject *gobj)
     ObjectInstance *priv = get_object_qdata(gobj);
     bool had_toggle_down, had_toggle_up;
 
-    g_object_weak_unref(priv->gobj, wrapped_gobj_dispose_notify, priv);
+    if (!priv->g_object_finalized)
+        g_object_weak_unref(gobj, wrapped_gobj_dispose_notify, priv);
 
     /* FIXME: this check fails when JS code runs after the main loop ends,
      * because the idle functions are not dispatched without a main loop.


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