lua-users home
lua-l archive

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


> This may be common knowledge, but I thought I'd mention it.
> 
> Calling lua_error() from a C/C++ function can result in 
> leaked resources.  This can be more subtle in C++ than in C.
> 
> int func( lua_State* L )
> {
>     std::vector< int > v;
>     ...
>     lua_error( L );
>     return 0;
> }
> 
> The vector's destructor never gets called and its memory is leaked.

I've run into this SO many times.  I'm not sure if it is doable, but perhaps
lua_error() should set a flag for the error condition and only fire when the
Lua VM is back in control?

Josh