Skip to content

Commit 72b6ea3

Browse files
committed
fix: free queue node and set async_pending flag before finalize
1 parent e1b47b4 commit 72b6ea3

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
@@ -173,6 +173,12 @@ const emnapiTSFN = {
173173
destroyQueue (func: number) {
174174
const queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false)
175175
if (queue) {
176+
let node = emnapiTSFN.loadSizeTypeValue(queue, false)
177+
while (node !== 0) {
178+
const next = emnapiTSFN.loadSizeTypeValue(node + POINTER_SIZE, false)
179+
_free(to64('node') as number)
180+
node = next
181+
}
176182
_free(to64('queue') as number)
177183
}
178184
},
@@ -631,6 +637,7 @@ const emnapiTSFN = {
631637
return
632638
}
633639
emnapiTSFN.setHandlesClosing(func, 1)
640+
Atomics.store(new Int32Array(wasmMemory.buffer), (func + emnapiTSFN.offset.async_pending) >>> 2, 1)
634641
emnapiCtx.features.setImmediate(() => {
635642
emnapiTSFN.finalize(func)
636643
})

0 commit comments

Comments
 (0)