diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-01 15:38:49 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-01 15:38:49 -0200 |
commit | 421e459684f7fdf483454d99c048b47783cb0611 (patch) | |
tree | 76d2212ac0872d3f59245ff23e43af8c2dd3d0fa | |
parent | 9d28b401527ccb41f544d431abe52da69e8beb3c (diff) | |
download | lua-421e459684f7fdf483454d99c048b47783cb0611.tar.gz lua-421e459684f7fdf483454d99c048b47783cb0611.tar.bz2 lua-421e459684f7fdf483454d99c048b47783cb0611.zip |
'luaS_resize' can raise memory errors
-rw-r--r-- | lgc.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.239 2017/11/23 19:29:04 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.240 2017/11/30 15:37:16 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -816,14 +816,19 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p) { | |||
816 | */ | 816 | */ |
817 | 817 | ||
818 | /* | 818 | /* |
819 | ** If possible, shrink string table | 819 | ** If possible, shrink string table (protected from memory errors). |
820 | */ | 820 | */ |
821 | static void shrinkstrtable (lua_State *L, void *ud) { | ||
822 | luaS_resize(L, *cast(int*, ud) / 2); | ||
823 | } | ||
824 | |||
825 | |||
821 | static void checkSizes (lua_State *L, global_State *g) { | 826 | static void checkSizes (lua_State *L, global_State *g) { |
822 | if (!g->gcemergency) { | 827 | if (!g->gcemergency) { |
823 | l_mem olddebt = g->GCdebt; | 828 | l_mem olddebt = g->GCdebt; |
824 | if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ | 829 | if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ |
825 | luaS_resize(L, g->strt.size / 2); /* shrink it a little */ | 830 | luaD_rawrunprotected(L, &shrinkstrtable, &g->strt.size); |
826 | g->GCestimate += g->GCdebt - olddebt; /* update estimate */ | 831 | g->GCestimate += g->GCdebt - olddebt; /* correct estimate */ |
827 | } | 832 | } |
828 | } | 833 | } |
829 | 834 | ||