Fix crash when handling multiple parallel requests.

---
 src/mozjs.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/mozjs.c b/src/mozjs.c
index ee935f3..8471816 100644
--- a/src/mozjs.c
+++ b/src/mozjs.c
@@ -38,6 +38,8 @@
 
 #include "pacrunner.h"
 
+static GStaticMutex mozjs_mutex = G_STATIC_MUTEX_INIT;
+
 struct pacrunner_proxy *current_proxy = NULL;
 
 static int getaddr(const char *node, char *host, size_t hostlen)
@@ -227,6 +229,7 @@ const char *__pacrunner_mozjs_execute(const char *url, 
const char *host)
                JS_free(jsctx, tmpurl);
                return NULL;
        }
+       g_static_mutex_lock(&mozjs_mutex);
 
        JS_BeginRequest(jsctx);
 
@@ -242,6 +245,8 @@ const char *__pacrunner_mozjs_execute(const char *url, 
const char *host)
 
        JS_MaybeGC(jsctx);
 
+       g_static_mutex_unlock(&mozjs_mutex);
+
        if (result) {
                answer = JS_GetStringBytes(JS_ValueToString(jsctx, rval));
                return answer;
-- 
1.7.3.2


_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to