Skip to content

Commit

Permalink
Free JS references to make process exit cleanly
Browse files Browse the repository at this point in the history
Fixes #40.
  • Loading branch information
TooTallNate committed Oct 5, 2023
1 parent 0e3264e commit dfa97ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-sloths-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Free JS references to make process exit cleanly
8 changes: 6 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ int main(int argc, char *argv[])
nx_init_tcp(ctx, native_obj);
nx_init_wasm(ctx, native_obj);

JSValue exit_func = JS_NewCFunction(ctx, js_exit, "exit", 0);
JS_SetPropertyStr(ctx, switch_obj, "exit", exit_func);
JS_SetPropertyStr(ctx, switch_obj, "exit", JS_NewCFunction(ctx, js_exit, "exit", 0));

const JSCFunctionListEntry function_list[] = {
JS_CFUNC_DEF("print", 1, js_print),
Expand Down Expand Up @@ -639,6 +638,11 @@ int main(int argc, char *argv[])
}
}

JS_FreeValue(ctx, switch_dispatch_func);
JS_FreeValue(ctx, native_obj);
JS_FreeValue(ctx, switch_obj);
JS_FreeValue(ctx, global_obj);

JS_FreeContext(ctx);
JS_FreeRuntime(rt);

Expand Down

0 comments on commit dfa97ae

Please sign in to comment.