lua-users home
lua-l archive

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


Could You please provide a little bit more details on the environment You'e working on? Is it eLua by any chance? Which kind of controller are we talking about?

On Wed, 10 Apr 2019, 12:02 Fotis Panagiotopoulos, <f.j.panag@gmail.com> wrote:

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).

  • Is it always safe to call lua_close()?
  • If a lua_pcall() fails, is it allowed to use again lua_pcall() calling another function?
  • In case lua_pcall() fails with "not enough memory", can any assumptions be made about the memory state? Can lua_close() be called then, or generally any other Lua API function?