[gjs] [function.c] Free cached invoker data, also free in _uncached



commit bed86b4357de7ebe5c719db4f117dca59ac383b5
Author: Colin Walters <walters verbum org>
Date:   Wed Apr 14 16:51:20 2010 -0400

    [function.c] Free cached invoker data, also free in _uncached
    
    The _uncached invocation path wasn't freeing the cached function
    data; make it do so.
    
    Also, for both the regular and _uncached path we need to free
    the invoker data.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=615222

 gi/function.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/gi/function.c b/gi/function.c
index ce03d62..0bf5744 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -787,6 +787,17 @@ function_constructor(JSContext *context,
     return JS_TRUE;
 }
 
+/* Does not actually free storage for structure, just
+ * reverses init_cached_function_data
+ */
+static void
+uninit_cached_function_data (Function *function)
+{
+    if (function->info)
+        g_base_info_unref( (GIBaseInfo*) function->info);
+    g_function_invoker_destroy(&function->invoker);
+}
+
 static void
 function_finalize(JSContext *context,
                   JSObject  *obj)
@@ -799,8 +810,7 @@ function_finalize(JSContext *context,
     if (priv == NULL)
         return; /* we are the prototype, not a real instance, so constructor never called */
 
-    if (priv->info)
-        g_base_info_unref( (GIBaseInfo*) priv->info);
+    uninit_cached_function_data(priv);
 
     GJS_DEC_COUNTER(function);
     g_slice_free(Function, priv);
@@ -1052,10 +1062,13 @@ gjs_invoke_c_function_uncached (JSContext      *context,
                                 jsval          *rval)
 {
   Function function;
+  JSBool result;
 
   memset (&function, 0, sizeof (Function));
   if (!init_cached_function_data (context, &function, info))
     return JS_FALSE;
 
-  return gjs_invoke_c_function (context, &function, obj, argc, argv, rval);
+  result = gjs_invoke_c_function (context, &function, obj, argc, argv, rval);
+  uninit_cached_function_data (&function);
+  return result;
 }



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