Description
In WasmModule.loadCore (src/types.zig), export_fns and cached_fns are allocated before the Wasm start function is executed.
If the start function traps (or otherwise returns an error), the errdefer chain cleans up vm, instance, wasi_ctx, module, store, and self, but never frees export_fns or cached_fns.
This is a narrow, pre-existing resource leak discovered during the review of #40. It is unrelated to the OOM-on-VM fix in that PR.
Steps to reproduce
- Prepare a Wasm module whose start function always traps (e.g., unreachable) and has at least one exported function so that export_fns / cached_fns are non-empty.
Example WAT:
(module
(func $start unreachable)
(func (export "dummy") (result i32) i32.const 0)
(start $start)
)
- Load it under a leak-checking allocator:
var gpa = std.heap.GeneralPurposeAllocator(.{ .safety = true }){};
defer _ = gpa.deinit(); // reports leak
_ = WasmModule.loadFromWat(gpa.allocator(), wat_source) catch {};
- Observe that gpa.deinit() reports memory leaks for export_fns (including the inner param_types / result_types slices) and cached_fns.
zwasm version
1.8.0
Platform
Linux x86_64
Additional context
No response
Description
In WasmModule.loadCore (src/types.zig), export_fns and cached_fns are allocated before the Wasm start function is executed.
If the start function traps (or otherwise returns an error), the errdefer chain cleans up vm, instance, wasi_ctx, module, store, and self, but never frees export_fns or cached_fns.
This is a narrow, pre-existing resource leak discovered during the review of #40. It is unrelated to the OOM-on-VM fix in that PR.
Steps to reproduce
Example WAT:
zwasm version
1.8.0
Platform
Linux x86_64
Additional context
No response