lua-users home
lua-l archive

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


2018-05-17 12:45 GMT+03:00 云风 Cloud Wu <cloudwu@gmail.com>:
> 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.

Thanks a lot!

Best regards,

-- 
DoubleF