global_State must be deallocated (and so allocated) with NULL also
(otherwise it trys to decrement inside itself after its own free)
This commit is contained in:
6
lmem.c
6
lmem.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lmem.c,v 1.58 2002/10/08 18:45:07 roberto Exp roberto $
|
** $Id: lmem.c,v 1.59 2002/10/25 21:29:20 roberto Exp roberto $
|
||||||
** Interface to Memory Manager
|
** Interface to Memory Manager
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -67,6 +67,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
|||||||
l_free(block, oldsize);
|
l_free(block, oldsize);
|
||||||
block = NULL;
|
block = NULL;
|
||||||
}
|
}
|
||||||
|
else return NULL; /* avoid `nblocks' computations when oldsize==size==0 */
|
||||||
}
|
}
|
||||||
else if (size >= MAX_SIZET)
|
else if (size >= MAX_SIZET)
|
||||||
luaG_runerror(L, "memory allocation error: block too big");
|
luaG_runerror(L, "memory allocation error: block too big");
|
||||||
@@ -78,7 +79,8 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
|||||||
else return NULL; /* error before creating state! */
|
else return NULL; /* error before creating state! */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (L && G(L)) {
|
if (L) {
|
||||||
|
lua_assert(G(L) != NULL && G(L)->nblocks > 0);
|
||||||
G(L)->nblocks -= oldsize;
|
G(L)->nblocks -= oldsize;
|
||||||
G(L)->nblocks += size;
|
G(L)->nblocks += size;
|
||||||
}
|
}
|
||||||
|
|||||||
7
lstate.c
7
lstate.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstate.c,v 1.112 2002/11/18 11:01:55 roberto Exp roberto $
|
** $Id: lstate.c,v 1.113 2002/11/19 14:12:13 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -84,8 +84,9 @@ static void freestack (lua_State *L, lua_State *L1) {
|
|||||||
*/
|
*/
|
||||||
static void f_luaopen (lua_State *L, void *ud) {
|
static void f_luaopen (lua_State *L, void *ud) {
|
||||||
/* create a new global state */
|
/* create a new global state */
|
||||||
global_State *g = luaM_new(L, global_State);
|
global_State *g = luaM_new(NULL, global_State);
|
||||||
UNUSED(ud);
|
UNUSED(ud);
|
||||||
|
if (g == NULL) luaD_throw(L, LUA_ERRMEM);
|
||||||
L->l_G = g;
|
L->l_G = g;
|
||||||
g->mainthread = L;
|
g->mainthread = L;
|
||||||
g->GCthreshold = 0; /* mark it as unfinished state */
|
g->GCthreshold = 0; /* mark it as unfinished state */
|
||||||
@@ -147,7 +148,7 @@ static void close_state (lua_State *L) {
|
|||||||
freestack(L, L);
|
freestack(L, L);
|
||||||
if (G(L)) {
|
if (G(L)) {
|
||||||
lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State));
|
lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State));
|
||||||
luaM_freelem(L, G(L));
|
luaM_freelem(NULL, G(L));
|
||||||
}
|
}
|
||||||
freestate(NULL, L);
|
freestate(NULL, L);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user