Skip to content

Commit

Permalink
compiler: add munmap finalizer on cache hits to avoid memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Val Packett <[email protected]>
  • Loading branch information
valpackett committed Oct 24, 2023
1 parent 610fdbd commit d285a81
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/engine/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ func (e *engine) Close() (err error) {

// CompileModule implements the same method as documented on wasm.Engine.
func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners []experimental.FunctionListener, ensureTermination bool) error {
if _, ok, err := e.getCompiledModule(module, listeners); ok { // cache hit!
if cm, ok, err := e.getCompiledModule(module, listeners); ok { // cache hit!
// As this uses mmap, we need to munmap on the compiled machine code when it's GCed.
e.setFinalizer(cm, releaseCompiledModule)
return nil
} else if err != nil {
return err
Expand Down

0 comments on commit d285a81

Please sign in to comment.