Skip to content

Commit

Permalink
fix: function bind lead to stack leak
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Feb 19, 2024
1 parent a163c41 commit 94d3d0d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wasmoon-lua5.1",
"version": "1.18.9",
"version": "1.18.10",
"description": "A real lua 5.1 VM with JS bindings made with webassembly",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export default class LuaThread {
return undefined;
} finally {
thread.close();
this.pop();
}
};
func.$isAlive = () => true;
Expand All @@ -259,7 +260,6 @@ export default class LuaThread {
func.$isAlive = () => false;
};
this.luaApi.pointerRefs.set(pointer, func);

return func;
}

Expand Down
34 changes: 22 additions & 12 deletions test/debug.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import { Lua } from '../dist/index.js';
const lua = await Lua.create();

await lua.doString(`
function Apply()
function Apply()
print(123)
end
end
`);
x = function ()
print(1)
return 1
end
z = function ()
print(1)
return 1
end
`);

console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);
console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);
console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);
const x = lua.ctx.x;
const y = lua.ctx.z;
console.log(x === y);
lua.global.dumpStack();
console.log('===========');
console.log(x());
lua.global.dumpStack();
console.log('===========');
console.log(x());
lua.global.dumpStack();
console.log('===========');
console.log(x());
lua.global.dumpStack();

0 comments on commit 94d3d0d

Please sign in to comment.