summaryrefslogtreecommitdiff
path: root/src/scripts.c
diff options
context:
space:
mode:
authorportix <none@none>2012-11-07 00:51:01 +0100
committerportix <none@none>2012-11-07 00:51:01 +0100
commitc745499e3b994c8ccc503dada279df60f5618f4b (patch)
tree54f92d22aeb936c9aae789e9f86c3d3783ed42d5 /src/scripts.c
parent773dbe7055f3c10ac2329803647fba405ac7cff8 (diff)
downloaddwb-c745499e3b994c8ccc503dada279df60f5618f4b.zip
Protect function in global_timer_start; fixes possible segfault
Diffstat (limited to 'src/scripts.c')
-rw-r--r--src/scripts.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/scripts.c b/src/scripts.c
index 2cde4e94..7d6be2c7 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -956,10 +956,17 @@ error_out:
/* timeout_callback {{{*/
static gboolean
timeout_callback(JSObjectRef obj) {
+ gboolean ret;
JSValueRef val = JSObjectCallAsFunction(m_global_context, obj, NULL, 0, NULL, NULL);
if (val == NULL)
- return false;
- return !JSValueIsBoolean(m_global_context, val) || JSValueToBoolean(m_global_context, val);
+ ret = false;
+ else {
+ ret = !JSValueIsBoolean(m_global_context, val) || JSValueToBoolean(m_global_context, val);
+ }
+ if (! ret )
+ JSValueUnprotect(m_global_context, obj);
+ return ret;
+
}/*}}}*/
/* global_timer_stop {{{*/
@@ -992,6 +999,7 @@ global_timer_start(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size
js_make_exception(ctx, exc, EXCEPTION("timerStart: argument 2 is not a function."));
return JSValueMakeNumber(ctx, -1);
}
+ JSValueProtect(ctx, func);
int ret = g_timeout_add((int)msec, (GSourceFunc)timeout_callback, func);
return JSValueMakeNumber(ctx, ret);
}/*}}}*/