Browse Source

More aggressive stack cleaning (see #37)

Dmitry Panov 8 years ago
parent
commit
613f33eefd
2 changed files with 10 additions and 0 deletions
  1. 2 0
      runtime.go
  2. 8 0
      vm.go

+ 2 - 0
runtime.go

@@ -812,6 +812,7 @@ func (r *Runtime) RunProgram(p *Program) (result Value, err error) {
 	if recursive {
 	if recursive {
 		r.vm.popCtx()
 		r.vm.popCtx()
 		r.vm.halt = false
 		r.vm.halt = false
+		r.vm.clearStack()
 	} else {
 	} else {
 		r.vm.stack = nil
 		r.vm.stack = nil
 	}
 	}
@@ -1317,6 +1318,7 @@ func AssertFunction(v Value) (Callable, bool) {
 				if ex != nil {
 				if ex != nil {
 					err = ex
 					err = ex
 				}
 				}
+				obj.runtime.vm.clearStack()
 				return
 				return
 			}, true
 			}, true
 		}
 		}

+ 8 - 0
vm.go

@@ -1837,6 +1837,14 @@ func (vm *vm) _nativeCall(f *nativeFuncObject, n int) {
 	vm.pc++
 	vm.pc++
 }
 }
 
 
+func (vm *vm) clearStack() {
+	stackTail := vm.stack[vm.sp:]
+	for i := range stackTail {
+		stackTail[i] = nil
+	}
+	vm.stack = vm.stack[:vm.sp]
+}
+
 type enterFunc uint32
 type enterFunc uint32
 
 
 func (e enterFunc) exec(vm *vm) {
 func (e enterFunc) exec(vm *vm) {