lua-users home
lua-l archive

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


>From Lua 5.3.4 lauxlib.c, the default lua_Alloc routine used by
luaL_newstate is:

static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
  (void)ud; (void)osize;  /* not used */
  if (nsize == 0) {
    free(ptr);
    return NULL;
  }
  else
    return realloc(ptr, nsize);
}

The documentation (and the assert in luaM_realloc_) specify that the
alloc routine must not return NULL when shrinking a block. However, the
standards for realloc() provide no such guarantee, and it can be easily
demonstrated that common implementations (I've tested with jemalloc, but
I'm told by others that it's also true of tcmalloc) will return NULL
when trying to shrink a block under certain conditions.

I haven't been able to make Lua actually fail (yet), but there is
clearly a false assumption here. (The fact that the assertion exists
suggests that someone thought it was a problem - whether because of the
possible recursive call into the garbage collector, or throwing an error
somewhere not expected...)

-- 
Andrew.