lua-users home
lua-l archive

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


I am using Lua 5.2.2.
It is running on an STM32F427VIT6 MCU. It is not eLua, the environment is wirtten from scratch (including the memory manager that I am using). I am using the official Lua code, with the only modification being the LTR patch as discribed be the eLua project.

At the moment, based on the latest tests I am quite confident that the problem is reproducible only when lua_pcall(L, 0, 0, 0) returns with a not enout memory. It seems that other errors do not trigger this problem. Ia have also checked that atpanic is never called.

Στις Τετ, 10 Απρ 2019 στις 12:40 μ.μ., ο/η Ką Mykolas <kamicc@gmail.com> έγραψε:
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?