[gjs] closure: Fix reference counting of closures, unbreak tests



commit 03ac265dc7d97d9c5e5ad81f6f8bfec1fefe42a3
Author: Stef Walter <stefw gnome org>
Date:   Wed Feb 13 13:03:19 2013 +0100

    closure: Fix reference counting of closures, unbreak tests
    
    Glib no longer finalizes type classes, plugin or not. So essentially gjs
    will 'leak' the classes that it registers in gjs_register_type().
    
    GClosures that have been associated with such leaked classes (eg: through
    g_signal_override_class_closure()) will leak too. However the javascript
    context, object and runtime associated with the Closure do not leak.
    
    Make our memory reference tracking for closures to track the javascript
    related contents of the Closure and not the GClosure itself.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693676

 gi/closure.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/gi/closure.c b/gi/closure.c
index 1d51aea..349c4f5 100644
--- a/gi/closure.c
+++ b/gi/closure.c
@@ -153,6 +153,8 @@ check_context_valid(Closure *c)
  * is under our control, it's unlikely that g_closure_invalidate() will ever
  * be called by anyone else, but in case it ever does, it's slightly better
  * to remove the "keep alive" here rather than in the finalize notifier.
+ *
+ * Unlike "dispose" invalidation only happens once.
  */
 static void
 closure_invalidated(gpointer data,
@@ -162,6 +164,7 @@ closure_invalidated(gpointer data,
 
     c = (Closure*) closure;
 
+    GJS_DEC_COUNTER(closure);
     gjs_debug_closure("Invalidating closure %p which calls object %p",
                       closure, c->obj);
 
@@ -238,12 +241,7 @@ closure_set_invalid(gpointer  data,
     self->obj = NULL;
     self->context = NULL;
     self->runtime = NULL;
-}
 
-static void
-closure_finalized(gpointer data,
-                  GClosure *closure)
-{
     GJS_DEC_COUNTER(closure);
 }
 
@@ -364,10 +362,6 @@ gjs_closure_new(JSContext  *context,
     c->unref_on_global_object_finalized = FALSE;
 
     GJS_INC_COUNTER(closure);
-    /* the finalize notifier right now is purely to track the counter
-     * of how many closures are alive.
-     */
-    g_closure_add_finalize_notifier(&c->base, NULL, closure_finalized);
 
     if (root_function) {
         /* Fully manage closure lifetime if so asked */


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