[gjs] value: handle argc == 0 in closure_marshal



commit a026cc5ec1ff8767c3372cf48c419dd2c66488a4
Author: Ray Strode <rstrode redhat com>
Date:   Mon Apr 1 21:46:15 2013 -0400

    value: handle argc == 0 in closure_marshal
    
    It's possible for a closure to have 0 arguments.
    
    When this happens we end up calling alloca(0) which is
    undefined.
    
    This commit protects against argc == 0.
    
    (concretely, I was seeing this happen from
     g_closure_invoke(clsoure, &result_value, 0, NULL, NULL) in glib's
     gsourceclosure.c: source_closure_callback function)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670200

 gi/value.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/gi/value.c b/gi/value.c
index 909742d..f61ca73 100644
--- a/gi/value.c
+++ b/gi/value.c
@@ -77,11 +77,13 @@ closure_marshal(GClosure        *closure,
     JS_BeginRequest(context);
 
     argc = n_param_values;
-    argv = g_newa(jsval, n_param_values);
     rval = JSVAL_VOID;
+    if (argc > 0) {
+        argv = g_newa(jsval, n_param_values);
 
-    gjs_set_values(context, argv, argc, JSVAL_VOID);
-    gjs_root_value_locations(context, argv, argc);
+        gjs_set_values(context, argv, argc, JSVAL_VOID);
+        gjs_root_value_locations(context, argv, argc);
+    }
     JS_AddValueRoot(context, &rval);
 
     if (marshal_data) {
@@ -141,7 +143,8 @@ closure_marshal(GClosure        *closure,
     }
 
  cleanup:
-    gjs_unroot_value_locations(context, argv, argc);
+    if (argc > 0)
+        gjs_unroot_value_locations(context, argv, argc);
     JS_RemoveValueRoot(context, &rval);
     JS_EndRequest(context);
 }


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