aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-01 15:38:49 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-01 15:38:49 -0200
commit421e459684f7fdf483454d99c048b47783cb0611 (patch)
tree76d2212ac0872d3f59245ff23e43af8c2dd3d0fa
parent9d28b401527ccb41f544d431abe52da69e8beb3c (diff)
downloadlua-421e459684f7fdf483454d99c048b47783cb0611.tar.gz
lua-421e459684f7fdf483454d99c048b47783cb0611.tar.bz2
lua-421e459684f7fdf483454d99c048b47783cb0611.zip
'luaS_resize' can raise memory errors
-rw-r--r--lgc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lgc.c b/lgc.c
index f4b8d6a4..f893e122 100644
--- a/lgc.c
+++ b/lgc.c
@@ -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*/
821static void shrinkstrtable (lua_State *L, void *ud) {
822 luaS_resize(L, *cast(int*, ud) / 2);
823}
824
825
821static void checkSizes (lua_State *L, global_State *g) { 826static 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