lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Sergey Zakharchenko <doublef.mobile@gmail.com>于2018年5月17日周四 下午4:22写道:
2018-05-17 10:51 GMT+03:00 云风 Cloud Wu <cloudwu@gmail.com>:
Sergey Zakharchenko <doublef.mobile@gmail.com>于2018年5月17日周四 下午3:25写道:
Hello,

I've noticed that https://www.lua.org/bugs.html#5.3.4-7 indicates that the problem has been around since 5.0, but I can't reproduce it on 5.1.4, 5.1.5 or 5.2.4. Is it a problem with the bug list entry, or am I not trying hard enough?

You are missing words : " assume that the 2nd memory allocation from now fails ", I guess you need a custom allocator to reproduce it.

Oh, thanks. So, there's still no fix or workaround for that, right?


A workaround can be :

----
diff --git a/src/ltable.c b/src/ltable.c
index d080189..b1c1469 100644
--- a/src/ltable.c
+++ b/src/ltable.c
@@ -337,10 +337,14 @@ void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
   unsigned int oldasize = t->sizearray;
   int oldhsize = allocsizenode(t);
   Node *nold = t->node;  /* save old hash ... */
-  if (nasize > oldasize)  /* array part must grow? */
-    setarrayvector(L, t, nasize);
   /* create new hash part with appropriate size */
   setnodevector(L, t, nhsize);
+  if (nasize > oldasize) { /* array part must grow? */
+    Node *temp = t->node;
+    t->node = nold;
+    setarrayvector(L, t, nasize);
+    t->node = temp;
+  }
   if (nasize < oldasize) {  /* array part must shrink? */
     t->sizearray = nasize;
     /* re-insert elements from vanishing slice */
----

It may cause a memory leak when the issue triggered , but no inconsistent state on the table.