[gjs/gnome-3-8] jsapi-util,object: Add missing JS_EndRequest calls



commit 54244c4706ac1804ed87ceaaaa64173f59b23ae4
Author: Ray Strode <rstrode redhat com>
Date:   Mon Apr 1 11:01:40 2013 -0400

    jsapi-util,object: Add missing JS_EndRequest calls
    
    There are a few early return cases where a JS_BeginRequest isn't
    getting paired with JS_EndRequest.
    
    This commit fixes those cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670200

 gi/object.c             |   26 +++++++++++++++-----------
 gjs/jsapi-util-string.c |    4 +++-
 gjs/jsapi-util.c        |   11 +++++++++--
 3 files changed, 27 insertions(+), 14 deletions(-)
---
diff --git a/gi/object.c b/gi/object.c
index bfb3a3c..03ec807 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -2172,6 +2172,7 @@ gjs_register_type(JSContext *cx,
     };
     guint32 i, n_interfaces;
     GType *iface_types;
+    JSBool retval = JS_FALSE;
 
     JS_BeginRequest(cx);
 
@@ -2180,21 +2181,21 @@ gjs_register_type(JSContext *cx,
                         "parent", &parent,
                         "name", &name,
                         "interfaces", &interfaces))
-        return JS_FALSE;
+        goto out;
 
     if (!parent)
-        return JS_FALSE;
+        goto out;
 
     if (!do_base_typecheck(cx, parent, JS_TRUE))
-        return JS_FALSE;
+        goto out;
 
     if (!JS_IsArrayObject(cx, interfaces)) {
         gjs_throw(cx, "Invalid parameter interfaces (expected Array)");
-        return JS_FALSE;
+        goto out;
     }
 
     if (!JS_GetArrayLength(cx, interfaces, &n_interfaces))
-        return JS_FALSE;
+        goto out;
 
     iface_types = g_alloca(sizeof(GType) * n_interfaces);
 
@@ -2205,13 +2206,13 @@ gjs_register_type(JSContext *cx,
         GType iface_type;
 
         if (!JS_GetElement(cx, interfaces, i, &iface_val))
-            return JS_FALSE;
+            goto out;
 
         if (!JSVAL_IS_OBJECT(iface_val) ||
             ((iface_type = gjs_gtype_get_actual_gtype(cx, JSVAL_TO_OBJECT(iface_val)))
              == G_TYPE_INVALID)) {
             gjs_throw(cx, "Invalid parameter interfaces (element %d was not a GType)", i);
-            return JS_FALSE;
+            goto out;
         }
 
         iface_types[i] = iface_type;
@@ -2219,7 +2220,7 @@ gjs_register_type(JSContext *cx,
 
     if (g_type_from_name(name) != G_TYPE_INVALID) {
         gjs_throw (cx, "Type name %s is already registered", name);
-        return JS_FALSE;
+        goto out;
     }
 
     parent_priv = priv_from_js(cx, parent);
@@ -2232,7 +2233,7 @@ gjs_register_type(JSContext *cx,
     g_type_query_dynamic_safe(parent_type, &query);
     if (G_UNLIKELY (query.type == 0)) {
         gjs_throw (cx, "Cannot inherit from a non-gjs dynamic type [bug 687184]");
-        return JS_FALSE;
+        goto out;
     }
 
     type_info.class_size = query.class_size;
@@ -2254,13 +2255,16 @@ gjs_register_type(JSContext *cx,
 
     /* create a custom JSClass */
     if (!gjs_define_object_class(cx, NULL, instance_type, &constructor, NULL))
-        return JS_FALSE;
+        goto out;
 
     JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(constructor));
 
+    retval = JS_TRUE;
+
+out:
     JS_EndRequest(cx);
 
-    return JS_TRUE;
+    return retval;
 }
 
 static JSBool
diff --git a/gjs/jsapi-util-string.c b/gjs/jsapi-util-string.c
index d72bf7f..31d5cbf 100644
--- a/gjs/jsapi-util-string.c
+++ b/gjs/jsapi-util-string.c
@@ -49,8 +49,10 @@ gjs_string_to_utf8 (JSContext  *context,
     str = JSVAL_TO_STRING(value);
 
     len = JS_GetStringEncodingLength(context, str);
-    if (len == (gsize)(-1))
+    if (len == (gsize)(-1)) {
+        JS_EndRequest(context);
         return JS_FALSE;
+    }
 
     if (utf8_string_p) {
         bytes = g_malloc((len + 1) * sizeof(char));
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 6eab2ed..33829a9 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -242,8 +242,10 @@ gjs_define_string_array(JSContext   *context,
 
     JS_BeginRequest(context);
 
-    if (!JS_EnterLocalRootScope(context))
+    if (!JS_EnterLocalRootScope(context)) {
+        JS_EndRequest(context);
         return JS_FALSE;
+    }
 
     if (array_length == -1)
         array_length = g_strv_length((char**)array_values);
@@ -353,13 +355,16 @@ gjs_value_debug_string(JSContext      *context,
                 str = JS_NewStringCopyZ(context, klass->name);
                 JS_ClearPendingException(context);
                 if (str == NULL) {
+                    JS_EndRequest(context);
                     return g_strdup("[out of memory copying class name]");
                 }
             } else {
                 gjs_log_exception(context, NULL);
+                JS_EndRequest(context);
                 return g_strdup("[unknown object]");
             }
         } else {
+            JS_EndRequest(context);
             return g_strdup("[unknown non-object]");
         }
     }
@@ -811,8 +816,10 @@ gjs_date_from_time_t (JSContext *context, time_t time)
 
     JS_BeginRequest(context);
 
-    if (!JS_EnterLocalRootScope(context))
+    if (!JS_EnterLocalRootScope(context)) {
+        JS_EndRequest(context);
         return JSVAL_VOID;
+    }
 
     if (!JS_GetClassObject(context, JS_GetGlobalObject(context), JSProto_Date,
                            &date_constructor))


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