Skip to content

Commit fe26c61

Browse files
Fix JSValue leak in Detach causing JS_FreeRuntime assert on Android
Napi::Detach now calls JS_FreeValue on all remaining JSValues in the handle scope stack before deleting the env. Previously unique_ptr only freed heap memory without decrementing QuickJS reference counts. Co-authored-by: Copilot <[email protected]>
1 parent 8657c54 commit fe26c61

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Core/Node-API/Source/env_quickjs.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ namespace Napi
5252
if (!JS_IsUndefined(env_ptr->has_own_property_function))
5353
{
5454
JS_FreeValue(env_ptr->context, env_ptr->has_own_property_function);
55+
env_ptr->has_own_property_function = JS_UNDEFINED;
5556
}
57+
58+
// Free all remaining JSValues in the handle scope stack
59+
for (auto& ptr : env_ptr->handle_scope_stack)
60+
{
61+
JS_FreeValue(env_ptr->context, *ptr);
62+
}
63+
env_ptr->handle_scope_stack.clear();
64+
5665
delete env_ptr;
5766
}
5867
}

0 commit comments

Comments
 (0)