diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 12:14:42 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-21 12:14:42 -0200 |
commit | d404f0c276e4a81d044be8c7647635acbe13ff06 (patch) | |
tree | 970eae141b7e091ad699cbd74b7423251f5eb83d | |
parent | 48e42261ac5be367c90d8079da3371509b5c325a (diff) | |
download | lua-d404f0c276e4a81d044be8c7647635acbe13ff06.tar.gz lua-d404f0c276e4a81d044be8c7647635acbe13ff06.tar.bz2 lua-d404f0c276e4a81d044be8c7647635acbe13ff06.zip |
global_State must be deallocated (and so allocated) with NULL also
(otherwise it trys to decrement inside itself after its own free)
-rw-r--r-- | lmem.c | 6 | ||||
-rw-r--r-- | lstate.c | 7 |
2 files changed, 8 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.58 2002/10/08 18:45:07 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.59 2002/10/25 21:29:20 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -67,6 +67,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { | |||
67 | l_free(block, oldsize); | 67 | l_free(block, oldsize); |
68 | block = NULL; | 68 | block = NULL; |
69 | } | 69 | } |
70 | else return NULL; /* avoid `nblocks' computations when oldsize==size==0 */ | ||
70 | } | 71 | } |
71 | else if (size >= MAX_SIZET) | 72 | else if (size >= MAX_SIZET) |
72 | luaG_runerror(L, "memory allocation error: block too big"); | 73 | 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) { | |||
78 | else return NULL; /* error before creating state! */ | 79 | else return NULL; /* error before creating state! */ |
79 | } | 80 | } |
80 | } | 81 | } |
81 | if (L && G(L)) { | 82 | if (L) { |
83 | lua_assert(G(L) != NULL && G(L)->nblocks > 0); | ||
82 | G(L)->nblocks -= oldsize; | 84 | G(L)->nblocks -= oldsize; |
83 | G(L)->nblocks += size; | 85 | G(L)->nblocks += size; |
84 | } | 86 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.112 2002/11/18 11:01:55 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.113 2002/11/19 14:12:13 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -84,8 +84,9 @@ static void freestack (lua_State *L, lua_State *L1) { | |||
84 | */ | 84 | */ |
85 | static void f_luaopen (lua_State *L, void *ud) { | 85 | static void f_luaopen (lua_State *L, void *ud) { |
86 | /* create a new global state */ | 86 | /* create a new global state */ |
87 | global_State *g = luaM_new(L, global_State); | 87 | global_State *g = luaM_new(NULL, global_State); |
88 | UNUSED(ud); | 88 | UNUSED(ud); |
89 | if (g == NULL) luaD_throw(L, LUA_ERRMEM); | ||
89 | L->l_G = g; | 90 | L->l_G = g; |
90 | g->mainthread = L; | 91 | g->mainthread = L; |
91 | g->GCthreshold = 0; /* mark it as unfinished state */ | 92 | g->GCthreshold = 0; /* mark it as unfinished state */ |
@@ -147,7 +148,7 @@ static void close_state (lua_State *L) { | |||
147 | freestack(L, L); | 148 | freestack(L, L); |
148 | if (G(L)) { | 149 | if (G(L)) { |
149 | lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); | 150 | lua_assert(G(L)->nblocks == sizeof(lua_State) + sizeof(global_State)); |
150 | luaM_freelem(L, G(L)); | 151 | luaM_freelem(NULL, G(L)); |
151 | } | 152 | } |
152 | freestate(NULL, L); | 153 | freestate(NULL, L); |
153 | } | 154 | } |