[gjs: 1/2] function: Check for invalid closure



commit d85214b041b7e3f352f6138516b4fe6084c42230
Author: Philip Chimento <philip chimento gmail com>
Date:   Thu Apr 19 00:21:53 2018 -0700

    function: Check for invalid closure
    
    In certain cases, it's possible that a GObject's dispose handler will try
    to call into JS code during the shutdown GC. That ought to be stopped
    with the check for _gjs_context_is_sweeping() in gjs_callback_closure(),
    but not when the closure is already invalidated; in that case we can't
    get to the GjsContext pointer, as it will have been nulled out in the
    GjsClosure struct.
    
    In that case, check first if we have an invalid closure (which is the
    same as checking that the GjsContext pointer is not null.)
    
    Closes #148.

 gi/function.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 94129802..13a7863e 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -200,6 +200,14 @@ gjs_callback_closure(ffi_cif *cif,
     g_assert(trampoline);
     gjs_callback_trampoline_ref(trampoline);
 
+    if (G_UNLIKELY(!gjs_closure_is_valid(trampoline->js_function))) {
+        warn_about_illegal_js_callback(trampoline, "during shutdown",
+            "destroying a Clutter actor or GTK widget with ::destroy signal "
+            "connected, or using the destroy(), dispose(), or remove() vfuncs");
+        gjs_callback_trampoline_unref(trampoline);
+        return;
+    }
+
     context = gjs_closure_get_context(trampoline->js_function);
     if (G_UNLIKELY(_gjs_context_is_sweeping(context))) {
         warn_about_illegal_js_callback(trampoline, "during garbage collection",


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