diff --git a/src/lib/libasync.js b/src/lib/libasync.js index c79e4f6bfccbf..bb6f31f479886 100644 --- a/src/lib/libasync.js +++ b/src/lib/libasync.js @@ -517,7 +517,7 @@ addToLibrary({ _load_secondary_module: async function() { // Mark the module as loading for the wasm module (so it doesn't try to load it again). wasmExports['load_secondary_module_status'].value = 1; - var imports = {'primary': wasmExports}; + var imports = {'primary': wasmRawExports}; // Replace '.wasm' suffix with '.deferred.wasm'. var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; await instantiateAsync(null, deferred, imports); diff --git a/src/postamble.js b/src/postamble.js index 9879161660884..def31977cf86d 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -289,6 +289,9 @@ function checkUnflushedContent() { #endif // ASSERTIONS var wasmExports; +#if SPLIT_MODULE +var wasmRawExports; +#endif #if MODULARIZE == 'instance' // In MODULARIZE=instance mode we delay most of the initialization work until diff --git a/src/preamble.js b/src/preamble.js index c9002009f05d2..c86347746ee1a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -514,7 +514,7 @@ var splitModuleProxyHandler = { #if RUNTIME_DEBUG dbg(`placeholder function called: ${base}`); #endif - var imports = {'primary': wasmExports}; + var imports = {'primary': wasmRawExports}; // Replace '.wasm' suffix with '.deferred.wasm'. loadSplitModule(secondaryFile, imports, base); #if RUNTIME_DEBUG @@ -734,6 +734,9 @@ function getWasmImports() { reportUndefinedSymbols(); #endif +#if SPLIT_MODULE + wasmRawExports = wasmExports; +#endif #if MEMORY64 || CAN_ADDRESS_2GB wasmExports = applySignatureConversions(wasmExports); #endif diff --git a/test/other/test_split_module.c b/test/other/test_split_module.c index a23e41e128931..4a46b391b559f 100644 --- a/test/other/test_split_module.c +++ b/test/other/test_split_module.c @@ -7,4 +7,12 @@ int foo() { EMSCRIPTEN_KEEPALIVE void say_hello() { printf("Hello! answer: %d\n", foo()); + + void* ptr = malloc(10); + if (ptr == NULL) { + return; + } + + free(ptr); + ptr = NULL; }