Skip to content

fix: free host call request in wasm-msg guest side#370

Closed
nicklasl wants to merge 2 commits intomainfrom
nicklasl/wasm-memory-leak-guest-side
Closed

fix: free host call request in wasm-msg guest side#370
nicklasl wants to merge 2 commits intomainfrom
nicklasl/wasm-memory-leak-guest-side

Conversation

@nicklasl
Copy link
Copy Markdown
Member

Summary

Alternative to #369 — fixes the same WASM memory leak but in a single place.

  • call_sync_host in wasm-msg allocates a request in WASM memory and passes it to the host function, but never frees it. This leaks ~20 bytes per resolve_flags/apply_flags call.
  • Fix by freeing input_ptr in call_sync_host after the host returns — mirroring how call_sync_guest already frees its input via consume_request
  • One Rust fix covers all host functions (current_time, log_message) across all providers
  • Java's consumeRequest changed to read-only to avoid double-free (it was the only provider that freed correctly before)
  • WASM memory regression tests added for Go, JS, Python, and Java

Test plan

  • Go: TestWasmMemoryStableOnRepeatedResolveCalls — 50k resolves, zero memory growth
  • JS: wasm memory stability — 50k resolves, zero memory growth
  • Python: test_multiple_resolves_dont_leak_memory — 50k resolves, zero memory growth
  • Java: wasmMemoryStableOnRepeatedResolveCalls — 50k resolves, zero memory growth

🤖 Generated with Claude Code

nicklasl and others added 2 commits April 14, 2026 11:59
call_sync_host allocates a request in WASM memory and passes it to the
host function, but never frees it. This leaks ~20 bytes per
resolve_flags/apply_flags call, causing unbounded memory growth.

Fix by freeing input_ptr in call_sync_host after the host returns,
mirroring how call_sync_guest already frees its input via
consume_request. This is a single fix that covers all host functions
(current_time, log_message) across all provider languages.

Java's consumeRequest is changed to read-only (no free) to avoid
double-free since the guest now owns deallocation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl nicklasl closed this Apr 14, 2026
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.

1 participant