[gjs] gi: Call init_object_private after creating JSObject for GObject
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] gi: Call init_object_private after creating JSObject for GObject
- Date: Sat, 17 Jan 2015 00:59:53 +0000 (UTC)
commit 0ed48e59f5956a21d4abb04372385ec4f49ad10f
Author: Sam Spilsbury <smspillaz gmail com>
Date: Wed Jan 7 09:10:08 2015 +0800
gi: Call init_object_private after creating JSObject for GObject
Previously we called this function in init_func (eg, _init), but
that left open a window for a garbage collection cycle to occurr
because we were getting and setting properties in the GObject
constructor which were calling into JS code.
When the newly constructed but not yet init'd object got traced,
a null pointer was dereferenced.
Fixes #742517
gi/object.cpp | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 4d3b805..cdc7775 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1250,7 +1250,7 @@ object_instance_init (JSContext *context,
JSObject *old_jsobj;
GObject *gobj;
- priv = init_object_private(context, *object);
+ priv = (ObjectInstance *) JS_GetPrivate(*object);
gtype = priv->gtype;
g_assert(gtype != G_TYPE_NONE);
@@ -1338,6 +1338,11 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(object_instance)
GJS_NATIVE_CONSTRUCTOR_PRELUDE(object_instance);
+ /* Init the private variable before we do anything else. If a garbage
+ * collection happens when calling the init function then this object
+ * might be traced and we will end up dereferencing a null pointer */
+ init_object_private(context, object);
+
object_init_name = gjs_context_get_const_string(context, GJS_STRING_GOBJECT_INIT);
if (!gjs_object_require_property(context, object, "GObject instance", object_init_name, &initer))
return JS_FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]