Fix Lua stack corruption problem

This commit is contained in:
TerryE 2018-03-26 03:44:10 +01:00
parent be53d5c9f3
commit d78c54accd
1 changed files with 3 additions and 0 deletions

View File

@ -144,8 +144,11 @@ static void correctstack (lua_State *L, TValue *oldstack) {
void luaD_reallocstack (lua_State *L, int newsize) { void luaD_reallocstack (lua_State *L, int newsize) {
TValue *oldstack = L->stack; TValue *oldstack = L->stack;
int realsize = newsize + 1 + EXTRA_STACK; int realsize = newsize + 1 + EXTRA_STACK;
int block_status = is_block_gc(L);
lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1);
set_block_gc(L); /* The GC MUST be blocked during stack reallocaiton */
luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue); luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);
if (!block_status) unset_block_gc(L); /* Honour the previous block status */
L->stacksize = realsize; L->stacksize = realsize;
L->stack_last = L->stack+newsize; L->stack_last = L->stack+newsize;
correctstack(L, oldstack); correctstack(L, oldstack);