mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-02 09:40:35 +00:00
vm: clear static slot refs on exit, fix #2501
This commit is contained in:
parent
711112ae40
commit
f2f66ad36e
2 changed files with 30 additions and 1 deletions
|
@ -1588,7 +1588,7 @@ func (v *VM) unloadContext(ctx *Context) {
|
|||
ctx.arguments.ClearRefs(&v.refs)
|
||||
}
|
||||
currCtx := v.Context()
|
||||
if ctx.static != nil && currCtx != nil && ctx.static != currCtx.static {
|
||||
if ctx.static != nil && (currCtx == nil || ctx.static != currCtx.static) {
|
||||
ctx.static.ClearRefs(&v.refs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2718,6 +2718,35 @@ func TestNestedStructEquals(t *testing.T) {
|
|||
checkVMFailed(t, vm)
|
||||
}
|
||||
|
||||
func TestRemoveReferrer(t *testing.T) {
|
||||
h := "560110c34a10c36058cf4540" // #2501
|
||||
prog, err := hex.DecodeString(h)
|
||||
require.NoError(t, err)
|
||||
vm := load(prog)
|
||||
require.NoError(t, vm.StepInto()) // INITSSLOT
|
||||
assert.Equal(t, 1, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // PUSH0
|
||||
assert.Equal(t, 2, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // NEWARRAY
|
||||
assert.Equal(t, 2, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // DUP
|
||||
assert.Equal(t, 3, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // PUSH0
|
||||
assert.Equal(t, 4, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // NEWARRAY
|
||||
assert.Equal(t, 4, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // STSFLD0
|
||||
assert.Equal(t, 3, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // LDSFLD0
|
||||
assert.Equal(t, 4, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // APPEND
|
||||
assert.Equal(t, 3, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // DROP
|
||||
assert.Equal(t, 1, int(vm.refs))
|
||||
require.NoError(t, vm.StepInto()) // RET
|
||||
assert.Equal(t, 0, int(vm.refs))
|
||||
}
|
||||
|
||||
func makeProgram(opcodes ...opcode.Opcode) []byte {
|
||||
prog := make([]byte, len(opcodes)+1) // RET
|
||||
for i := 0; i < len(opcodes); i++ {
|
||||
|
|
Loading…
Add table
Reference in a new issue