Skip to content

Commit

Permalink
fix(vm): Release VM properly.
Browse files Browse the repository at this point in the history
Properly clean slices using make (the internal logic is expecting slices
to not be nil).

It closes #1033

Signed-off-by: Antonio Navarro Perez <[email protected]>
  • Loading branch information
ajnavarro committed Sep 13, 2023
1 parent 207d66d commit 1c27a0f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ var (
// and prevent objects that were not taken from
// the pool, to call Release
func (m *Machine) Release() {
// copy()
// here we zero in the values for the next user
m.NumOps = 0
m.NumValues = 0
// this is the fastest way to zero-in a slice in Go
copy(m.Ops, opZeroed[:])
copy(m.Values, valueZeroed[:])

m.Ops = make([]Op, 1024)
m.Values = make([]TypedValue, 1024)
m.Exprs = make([]Expr, 1024)
m.Stmts = make([]Stmt, 1024)
m.Blocks = make([]*Block, 1024)
m.Frames = make([]Frame, 1024)

machinePool.Put(m)
}
Expand Down

0 comments on commit 1c27a0f

Please sign in to comment.