[go: up one dir, main page]

Skip to content

Using STANDALONE_WASM with emmalloc the second call to malloc fails if free was never called on allocation with size > 48 #22628

Closed Answered by peterhirn
peterhirn asked this question in Q&A
Discussion options

You must be logged in to vote

Figured it out. I have to call instance.exports._initialize() to make this work.

import { readFile } from "node:fs/promises";

const binary = await readFile("./src/argon2.wasm");

const emscripten_notify_memory_growth = (memoryIndex) =>
  console.log("emscripten_notify_memory_growth", memoryIndex);

const imports = { emscripten_notify_memory_growth };
const $imports = { env: imports, wasi_snapshot_preview1: imports };
const { instance } = await WebAssembly.instantiate(binary, $imports);

instance.exports._initialize();

console.log(instance.exports.malloc(10));
console.log(instance.exports.malloc(10));
console.log(instance.exports.malloc(10));
69064
69088
69112

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by peterhirn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant