summaryrefslogtreecommitdiff
path: root/src/scripts.c
diff options
context:
space:
mode:
authorportix <none@none>2013-02-16 14:11:29 +0100
committerportix <none@none>2013-02-16 14:11:29 +0100
commita628c3f21439a248d15e06d0d91d8ca6315e8aa9 (patch)
tree426aea2ff22a5708cc7ab3964c314c581cc1110a /src/scripts.c
parente0061a63ef72294326f4b6f2e3a0ba3018ec2a50 (diff)
downloaddwb-a628c3f21439a248d15e06d0d91d8ca6315e8aa9.zip
Lock s_global_context when destroying objects, protect all gui elements, prevents segfault when closing dwb and the context has already been destroyed
Diffstat (limited to 'src/scripts.c')
-rw-r--r--src/scripts.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/scripts.c b/src/scripts.c
index dc649d27..cf8d0e4d 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -41,6 +41,8 @@
#define PROP_LENGTH 128
#define G_FILE_TEST_VALID (G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK | G_FILE_TEST_IS_DIR | G_FILE_TEST_IS_EXECUTABLE | G_FILE_TEST_EXISTS)
+static pthread_mutex_t s_context_mutex = PTHREAD_MUTEX_INITIALIZER;
+
typedef struct Sigmap_s {
int sig;
const char *name;
@@ -1995,57 +1997,57 @@ download_cancel(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t
static JSValueRef
gui_get_window(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.window), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.window), true);
}
static JSValueRef
gui_get_main_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.vbox), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.vbox), true);
}
static JSValueRef
gui_get_tab_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.topbox), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.topbox), true);
}
static JSValueRef
gui_get_content_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.mainbox), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.mainbox), true);
}
static JSValueRef
gui_get_status_widget(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.statusbox), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.statusbox), true);
}
static JSValueRef
gui_get_status_alignment(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.alignment), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.alignment), true);
}
static JSValueRef
gui_get_status_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.status_hbox), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.status_hbox), true);
}
static JSValueRef
gui_get_message_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.lstatus), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.lstatus), true);
}
static JSValueRef
gui_get_entry(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.entry), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.entry), true);
}
static JSValueRef
gui_get_uri_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.urilabel), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.urilabel), true);
}
static JSValueRef
gui_get_status_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
- return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.rstatus), false);
+ return make_object_for_class(ctx, s_gobject_class, G_OBJECT(dwb.gui.rstatus), true);
}
/*}}}*/
@@ -2123,8 +2125,13 @@ scripts_emit(ScriptSignal *sig)
static void
object_destroy_cb(JSObjectRef o)
{
- JSObjectSetPrivate(o, NULL);
- JSValueUnprotect(s_global_context, o);
+ pthread_mutex_lock(&s_context_mutex);
+ if (s_global_context)
+ {
+ JSObjectSetPrivate(o, NULL);
+ JSValueUnprotect(s_global_context, o);
+ }
+ pthread_mutex_unlock(&s_context_mutex);
}
static JSObjectRef
@@ -3009,6 +3016,7 @@ scripts_unbind(JSObjectRef obj)
void
scripts_end()
{
+ pthread_mutex_lock(&s_context_mutex);
if (s_global_context != NULL)
{
for (int i=0; i<CONSTRUCTOR_LAST; i++)
@@ -3031,4 +3039,5 @@ scripts_end()
JSGlobalContextRelease(s_global_context);
s_global_context = NULL;
}
+ pthread_mutex_unlock(&s_context_mutex);
}/*}}}*//*}}}*/