Gracefully handle broken custom allocator.

Reported by Alex Orlenko. #1393
This commit is contained in:
Mike Pall
2025-10-16 13:23:51 +02:00
parent a21ba1c9b5
commit 5c3254d68d

View File

@@ -261,7 +261,11 @@ LUA_API lua_State *lua_newstate(lua_Alloc allocf, void *allocd)
} }
#endif #endif
GG = (GG_State *)allocf(allocd, NULL, 0, sizeof(GG_State)); GG = (GG_State *)allocf(allocd, NULL, 0, sizeof(GG_State));
if (GG == NULL || !checkptrGC(GG)) return NULL; if (GG == NULL) return NULL;
if (!checkptrGC(GG)) {
allocf(allocd, GG, sizeof(GG_State), 0);
return NULL;
}
memset(GG, 0, sizeof(GG_State)); memset(GG, 0, sizeof(GG_State));
L = &GG->L; L = &GG->L;
g = &GG->g; g = &GG->g;