Skip to content

Commit 71b77fb

Browse files
committed
fix: free queue node and set async_pending flag before finalize
1 parent b0cc8cc commit 71b77fb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

packages/emnapi/src/threadsafe-function.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ export const emnapiTSFN = {
157157
destroyQueue (func: number) {
158158
const queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false)
159159
if (queue) {
160+
let node = emnapiTSFN.loadSizeTypeValue(queue, false)
161+
while (node !== 0) {
162+
const next = emnapiTSFN.loadSizeTypeValue(node + POINTER_SIZE, false)
163+
_free(to64('node') as number)
164+
node = next
165+
}
160166
_free(to64('queue') as number)
161167
}
162168
},
@@ -616,6 +622,7 @@ export const emnapiTSFN = {
616622
return
617623
}
618624
emnapiTSFN.setHandlesClosing(func, 1)
625+
Atomics.store(new Int32Array(wasmMemory.buffer), (func + emnapiTSFN.offset.async_pending) >>> 2, 1)
619626
emnapiCtx.feature.setImmediate(() => {
620627
emnapiTSFN.finalize(func)
621628
})

0 commit comments

Comments
 (0)