mruby/mruby — pull request #1184 by tsahara-iij (2013-04-17 04:29:24+00:00)
Title: Rollback stack before executing ensure clause.

VM stack may be broken in an ensure clause under certain conditions.

```Ruby
class A
def a
r = @e = false
begin
b
rescue TypeError
r = self.z
end
[ r, @e ]
end

def b
begin
1 * "b"
ensure
@e = self.z
end
end

def z
true
end
end
p A.new.a
```

```
% ruby c1.rb
[true, true]

% mruby c1.rb
trace:
[1] ../mruby-gems/c.rb:7:in A.a
[0] ../mruby-gems/c.rb:24
c1.rb:7: undefined method 'z' for 1 (NoMethodError)
```

mruby raises an exception because "self" is not an instance of A in that ensure clause. Instead, it is 1, which is the receiver of the "*" method that has raised a TypeError exception. That's because VM stack ``mrb->stack`` points to wrong position.