Skip to content

Memory growth invalidates ctxPtrOut, causing unmanaged context creation in executePendingJobs #240

@arfelious

Description

@arfelious

Inside the executePendingJobs function, the view used for ctxPtrOut is allocated before the FFI call. If QTS_ExecutePendingJob triggers a WASM memory growth, the TypedArray backing ctxPtrOut becomes detached.

    const ctxPtrOut = this.memory.newMutablePointerArray<JSContextPointerPointer>(1)
    const valuePtr = this.ffi.QTS_ExecutePendingJob(
      this.rt.value,
      maxJobsToExecute ?? -1,
      ctxPtrOut.value.ptr,
    )

When the code reads from this invalid view:

    const context =
      this.contextMap.get(ctxPtr) ??
      this.newContext({
        contextPointer: ctxPtr,
      })

The code enters the fallback path, an unmanaged context is created that cannot be disposed of, and internal context tracking is invalidated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions