Skip to content

Free input provider callbacks on cleanup - #167

Merged
jameslan merged 2 commits into
jameslan:masterfrom
shunkica:fix/input-provider-table-leak
Aug 25, 2026
Merged

jameslan merged 2 commits into
jameslan:masterfrom
shunkica:fix/input-provider-table-leak

Conversation

@shunkica

@shunkica shunkica commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #166

Fix

xmlRegisterInputProvider adds four wasm function-table entries per call, one per
callback closure (match/open/read/close), and xmlCleanupInputProvider
reclaimed none of them. addFunction cannot reuse an entry until removeFunction
releases it, so every register grew the table by four permanently and pinned the
provider, and any buffers it captured, for the process lifetime.

  • binding/exported-runtime-functions.txt exports removeFunction
    (-s ALLOW_TABLE_GROWTH=1 is already set, so no other emcc change is needed).
  • src/libxml2.mts tracks the entries of each registration and releases them in
    cleanup. libxml2 keeps owning the callback stack and its precedence, and the
    provider's file descriptors still pass straight through.

@shunkica
shunkica force-pushed the fix/input-provider-table-leak branch 2 times, most recently from c4830c6 to 0e877cd Compare August 4, 2026 09:38
xmlRegisterInputProvider adds four wasm function-table entries per call,
one per callback closure, and xmlCleanupInputProvider reclaimed none of
them. addFunction cannot reuse an entry until removeFunction releases it,
so every register grew the table by four permanently and pinned the
provider and its buffers for the process lifetime.

Export Emscripten's removeFunction, track the entries of each
registration and release them in cleanup. A registration that libxml2
refuses now frees its entries as well, instead of stranding them.
@shunkica
shunkica force-pushed the fix/input-provider-table-leak branch from 0e877cd to 6d2c0a0 Compare August 4, 2026 09:45
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/input-provider-table-leak into master will be

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   c14n.mts100%100%100%100%
   diag.mts99.51%100%90.91%100%
   disposable.mts100%100%100%100%
   disposeShim.mts100%100%100%100%
   document.mts100%100%100%100%
   dtd.mts100%100%100%100%
   index.mts100%100%100%100%
   libxml2.mts100%100%100%100%
   metadataShim.mts100%100%100%100%
   nodejs.mts100%100%100%100%
   nodes.mts99.92%99.22%100%100%76
   utils.mts100%100%100%100%
   validates.mts100%100%100%100%
   xpath.mts100%100%100%100%

@jameslan
jameslan merged commit bb64429 into jameslan:master Aug 25, 2026
14 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 25, 2026
jameslan added a commit that referenced this pull request Sep 5, 2026
xmlRegisterInputProvider adds four wasm function-table entries per call,
one per callback closure, and xmlCleanupInputProvider reclaimed none of
them. addFunction cannot reuse an entry until removeFunction releases it,
so every register grew the table by four permanently and pinned the
provider and its buffers for the process lifetime.

Export Emscripten's removeFunction, track the entries of each
registration and release them in cleanup. A registration that libxml2
refuses now frees its entries as well, instead of stranding them.

Co-authored-by: James Lan <jameslan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xmlRegisterInputProvider leaks wasm function-table entries on every register/cleanup cycle

2 participants