summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/js/binaryen.js-post.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 35f5d9a5c..1101c1aab 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -2569,13 +2569,13 @@ function wrapModule(module, self = {}) {
const segmentOffset = new Array(segmentsLen);
for (let i = 0; i < segmentsLen; i++) {
const { data, offset, passive } = segments[i];
- segmentData[i] = stackAlloc(data.length);
+ segmentData[i] = _malloc(data.length);
HEAP8.set(data, segmentData[i]);
segmentDataLen[i] = data.length;
segmentPassive[i] = passive;
segmentOffset[i] = offset;
}
- return Module['_BinaryenSetMemory'](
+ const ret = Module['_BinaryenSetMemory'](
module, initial, maximum, strToStack(exportName),
i32sToStack(segmentData),
i8sToStack(segmentPassive),
@@ -2586,6 +2586,10 @@ function wrapModule(module, self = {}) {
memory64,
strToStack(internalName)
);
+ for (let i = 0; i < segmentsLen; i++) {
+ _free(segmentData[i]);
+ }
+ return ret;
});
};
self['hasMemory'] = function() {