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 /lmem.c | |
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)
Diffstat (limited to '')
-rw-r--r-- | lmem.c | 6 |
1 files changed, 4 insertions, 2 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 | } |