Avoid setting the stack top below upvalues to be closed

When leaving a scope, the new stack top should be set only after
closing any upvalue, to avoid manipulating values in an "invalid"
part of the stack.
This commit is contained in:
Roberto Ierusalimschy
2019-07-16 14:13:22 -03:00
parent 758c1ef445
commit 298f383ffc
3 changed files with 13 additions and 9 deletions

View File

@@ -202,6 +202,7 @@ int luaF_close (lua_State *L, StkId level, int status) {
while ((uv = L->openupval) != NULL && uplevel(uv) >= level) {
StkId upl = uplevel(uv);
TValue *slot = &uv->u.value; /* new position for value */
lua_assert(upl < L->top);
luaF_unlinkupval(uv);
setobj(L, slot, uv->v); /* move value to upvalue slot */
uv->v = slot; /* now current value lives here */