Skip to content

Commit

Permalink
Clear allocator when closing instance
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jul 22, 2022
1 parent d6cf546 commit 2ee6693
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/runtime/wasmer/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,25 @@ func (in *Instance) SetContextStorage(s runtime.Storage) {
in.ctx.Storage = s
}

// Stop closes the instance (wasm instance and its imports)
// in a thread-safe way.
// Stop closes the WASM instance, its imports and clears
// the context allocator in a thread-safe way.
func (in *Instance) Stop() {
in.mutex.Lock()
defer in.mutex.Unlock()
in.close()
}

// close closes the wasm instance (and its imports)
// if the instance has not been previously closed.
// and clears the context allocator. If the instance
// has previously been closed, it simply returns.
// It is NOT THREAD SAFE to use.
func (in *Instance) close() {
if in.isClosed {
return
}

in.vm.Close()
in.ctx.Allocator.Clear()
in.isClosed = true
}

Expand Down

0 comments on commit 2ee6693

Please sign in to comment.