lua-users home
lua-l archive

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


Andrew Gierth <andrew@tao11.riddles.org.uk>于2017年11月24日周五 下午8:12写道:
>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);
}


There is another problem here.

If realloc failed, it doesn't free ptr. It cause a memory leak.