lua-users home
lua-l archive

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


I am using Lua in a microcontroller environment, and recently I had some crashes related to corruption of the heap data.

The issue was tracked down to be the following sequence:

  1. Call to lua_pcall(L, 0, 0, 0) without checking the return value.
  2. Call to another function, again with lua_pcall(L, 0, 0, 0), this time checking the return value.
  3. Step 2 fails (as in fact step 1 had failed, but I didn't catch it), and calls lua_close(L);
  4. During lua_close(L) memory is deallocated. At this stage the memory manager detects a corruption to the heap, and the firmware crashes.

I would like to ask, at which cases can a Lua state be invalid? (And thus no other operations are allowed).