fix: free host call request in wasm-msg guest side#370
Closed
fix: free host call request in wasm-msg guest side#370
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Alternative to #369 — fixes the same WASM memory leak but in a single place.
call_sync_hostinwasm-msgallocates a request in WASM memory and passes it to the host function, but never frees it. This leaks ~20 bytes perresolve_flags/apply_flagscall.input_ptrincall_sync_hostafter the host returns — mirroring howcall_sync_guestalready frees its input viaconsume_requestcurrent_time,log_message) across all providersconsumeRequestchanged to read-only to avoid double-free (it was the only provider that freed correctly before)Test plan
TestWasmMemoryStableOnRepeatedResolveCalls— 50k resolves, zero memory growthwasm memory stability— 50k resolves, zero memory growthtest_multiple_resolves_dont_leak_memory— 50k resolves, zero memory growthwasmMemoryStableOnRepeatedResolveCalls— 50k resolves, zero memory growth🤖 Generated with Claude Code