Skip to content

Commit 5b6b266

Browse files
committed
Release ref_count for import statement loaded resources
1 parent cd1bc60 commit 5b6b266

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

quickjs/quickjs_binder.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ JSModuleDef *QuickJSBinder::js_module_loader(JSContext *ctx, const char *module_
500500
JS_EvalFunction(ctx, func);
501501
JSValue val = variant_to_var(ctx, res);
502502
JS_SetModuleExport(ctx, m, "default", val);
503-
JS_FreeValue(ctx, val);
504503

505504
ModuleCache module;
506505
module.md5 = FileAccess::get_md5(file);
507506
module.module = m;
507+
module.res_value = val;
508508
module.flags = MODULE_FLAG_RESOURCE;
509509
module.module = static_cast<JSModuleDef *>(JS_VALUE_GET_PTR(func));
510510
binder->module_cache.set(file, module);
@@ -553,6 +553,7 @@ QuickJSBinder::ModuleCache *QuickJSBinder::js_compile_module(JSContext *ctx, con
553553
module.module = NULL;
554554
module.flags = MODULE_FLAG_SCRIPT;
555555
module.module = static_cast<JSModuleDef *>(JS_VALUE_GET_PTR(func));
556+
module.res_value = JS_UNDEFINED;
556557
binder->module_cache.set(p_filename, module);
557558
} else {
558559
JSValue e = JS_GetException(ctx);
@@ -1144,17 +1145,20 @@ void QuickJSBinder::uninitialize() {
11441145
frame_callbacks.clear();
11451146

11461147
{ // modules
1147-
#if MODULE_HAS_REFCOUNT
1148+
11481149
const String *file = module_cache.next(NULL);
11491150
while (file) {
11501151
const ModuleCache &m = module_cache.get(*file);
1152+
#if MODULE_HAS_REFCOUNT
11511153
if (m.module) {
11521154
JSValue val = JS_MKPTR(JS_TAG_MODULE, m.module);
11531155
JS_FreeValue(ctx, val);
11541156
}
1157+
#endif
1158+
JS_FreeValue(ctx, m.res_value);
11551159
file = module_cache.next(file);
11561160
}
1157-
#endif
1161+
11581162
module_cache.clear();
11591163
}
11601164

quickjs/quickjs_binder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class QuickJSBinder : public ECMAScriptBinder {
5252
struct ModuleCache {
5353
int flags;
5454
JSModuleDef *module;
55+
JSValue res_value;
5556
String md5;
5657
};
5758

0 commit comments

Comments
 (0)