mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Fix leak when interpreter exits due to exception
Fixes: https://github.com/quickjs-ng/quickjs/issues/720
This commit is contained in:
parent
9631492534
commit
f7f70fc579
8 changed files with 25 additions and 6 deletions
Binary file not shown.
BIN
gen/hello.c
BIN
gen/hello.c
Binary file not shown.
Binary file not shown.
BIN
gen/test_fib.c
BIN
gen/test_fib.c
Binary file not shown.
2
qjs.c
2
qjs.c
|
@ -36,6 +36,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "cutils.h"
|
#include "cutils.h"
|
||||||
|
#include "quickjs.h"
|
||||||
#include "quickjs-libc.h"
|
#include "quickjs-libc.h"
|
||||||
|
|
||||||
#ifdef QJS_USE_MIMALLOC
|
#ifdef QJS_USE_MIMALLOC
|
||||||
|
@ -556,6 +557,7 @@ int main(int argc, char **argv)
|
||||||
ret = js_std_loop(ctx);
|
ret = js_std_loop(ctx);
|
||||||
if (!JS_IsUndefined(ret)) {
|
if (!JS_IsUndefined(ret)) {
|
||||||
js_std_dump_error1(ctx, ret);
|
js_std_dump_error1(ctx, ret);
|
||||||
|
JS_FreeValue(ctx, ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
qjsc.c
14
qjsc.c
|
@ -314,19 +314,27 @@ static void compile_file(JSContext *ctx, FILE *fo,
|
||||||
static const char main_c_template1[] =
|
static const char main_c_template1[] =
|
||||||
"int main(int argc, char **argv)\n"
|
"int main(int argc, char **argv)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
" int r;\n"
|
||||||
|
" JSValue ret;\n"
|
||||||
" JSRuntime *rt;\n"
|
" JSRuntime *rt;\n"
|
||||||
" JSContext *ctx;\n"
|
" JSContext *ctx;\n"
|
||||||
|
" r = 0;\n"
|
||||||
" rt = JS_NewRuntime();\n"
|
" rt = JS_NewRuntime();\n"
|
||||||
" js_std_set_worker_new_context_func(JS_NewCustomContext);\n"
|
" js_std_set_worker_new_context_func(JS_NewCustomContext);\n"
|
||||||
" js_std_init_handlers(rt);\n"
|
" js_std_init_handlers(rt);\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
static const char main_c_template2[] =
|
static const char main_c_template2[] =
|
||||||
" js_std_loop(ctx);\n"
|
" ret = js_std_loop(ctx);\n"
|
||||||
|
" if (JS_IsException(ret)) {\n"
|
||||||
|
" js_std_dump_error1(ctx, ret);\n"
|
||||||
|
" r = 1;\n"
|
||||||
|
" }\n"
|
||||||
|
" JS_FreeValue(ctx, ret);\n"
|
||||||
" JS_FreeContext(ctx);\n"
|
" JS_FreeContext(ctx);\n"
|
||||||
" js_std_free_handlers(rt);\n"
|
" js_std_free_handlers(rt);\n"
|
||||||
" JS_FreeRuntime(rt);\n"
|
" JS_FreeRuntime(rt);\n"
|
||||||
" return 0;\n"
|
" return r;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
#define PROG_NAME "qjsc"
|
#define PROG_NAME "qjsc"
|
||||||
|
@ -375,7 +383,7 @@ int main(int argc, char **argv)
|
||||||
stack_size = 0;
|
stack_size = 0;
|
||||||
memset(&dynamic_module_list, 0, sizeof(dynamic_module_list));
|
memset(&dynamic_module_list, 0, sizeof(dynamic_module_list));
|
||||||
|
|
||||||
|
|
||||||
/* add system modules */
|
/* add system modules */
|
||||||
namelist_add(&cmodule_list, "qjs:std", "std", 0);
|
namelist_add(&cmodule_list, "qjs:std", "std", 0);
|
||||||
namelist_add(&cmodule_list, "qjs:os", "os", 0);
|
namelist_add(&cmodule_list, "qjs:os", "os", 0);
|
||||||
|
|
|
@ -3499,7 +3499,7 @@ static void *worker_func(void *opaque)
|
||||||
js_std_dump_error(ctx);
|
js_std_dump_error(ctx);
|
||||||
JS_FreeValue(ctx, val);
|
JS_FreeValue(ctx, val);
|
||||||
|
|
||||||
js_std_loop(ctx);
|
JS_FreeValue(ctx, js_std_loop(ctx));
|
||||||
|
|
||||||
JS_FreeContext(ctx);
|
JS_FreeContext(ctx);
|
||||||
js_std_free_handlers(rt);
|
js_std_free_handlers(rt);
|
||||||
|
@ -4137,6 +4137,7 @@ JSValue js_std_loop(JSContext *ctx)
|
||||||
JSRuntime *rt = JS_GetRuntime(ctx);
|
JSRuntime *rt = JS_GetRuntime(ctx);
|
||||||
JSThreadState *ts = js_get_thread_state(rt);
|
JSThreadState *ts = js_get_thread_state(rt);
|
||||||
JSContext *ctx1;
|
JSContext *ctx1;
|
||||||
|
JSValue ret;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
@ -4156,7 +4157,9 @@ JSValue js_std_loop(JSContext *ctx)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
return ts->exc;
|
ret = ts->exc;
|
||||||
|
ts->exc = JS_UNDEFINED;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a promise and execute pending jobs while waiting for
|
/* Wait for a promise and execute pending jobs while waiting for
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef pthread_t js_thread_t;
|
||||||
|
|
||||||
#include "cutils.h"
|
#include "cutils.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "quickjs.h"
|
||||||
#include "quickjs-c-atomics.h"
|
#include "quickjs-c-atomics.h"
|
||||||
#include "quickjs-libc.h"
|
#include "quickjs-libc.h"
|
||||||
|
|
||||||
|
@ -1554,7 +1555,12 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local) {
|
if (local) {
|
||||||
js_std_loop(ctx);
|
JSValue val = js_std_loop(ctx);
|
||||||
|
if (JS_IsException(val)) {
|
||||||
|
js_std_dump_error1(ctx, val);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
JS_FreeValue(ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FreeCString(ctx, error_name);
|
JS_FreeCString(ctx, error_name);
|
||||||
|
|
Loading…
Reference in a new issue