Menu

#36 segfault when exiting lua interpreter

next release
closed-fixed
nobody
None
5
2020-09-06
2015-12-20
No

Hi,

I'm encountering a segfault with the latest wxlua svn commit 251 on a current arch linux system using the package wxlua-svn from AUR [1] (that I maintain). The package is pretty much a vanilla wxlua. It is reproducible with e.g.

$ lua5.2 -e 'require("wx")'

The file "sigsegv" attached to this ticket has more information: According to the stacktrace the segfault occurs in lua_pushlightuserdata() called from the wxLuaState destructor. lua_pushlightuserdata() apparently dereferences the lua_State member top which looks like it is NULL (see disassembly and register info in file "sigsegv").

My guess is that the lua environment (represented by the lua_State struct m_lua_State) is freed before the wxLuaState destructor is run? I also attached a fix (wxluastate.patch) that checks if m_lua_State is still valid (lua_status() returns LUA_OK) before using it in wxLuaState::CloseLuaState(). This patch will soon be added to the AUR package [1]. Please let me know if this patch is ok or complete nonsense.

Best regards,

migerh

[1] https://aur.archlinux.org/packages/wxlua-svn
[2] http://www.lua.org/source/5.2/lapi.c.html

2 Attachments

Discussion

  • John Labenski

    John Labenski - 2016-05-03

    I do not get this error on Fedora 20 using the built-in lua 5.2.

    The first line of wxLuaStateRefData::CloseLuaState() checks to see if the m_lua_State is NULL. Based on the strack trace and the way the wxlua module works, there is just one static wxLuaState object so its destructor should only be called once and that is the only place where lua_close() is called and the m_lua_State NULLed.

    Can you provide any more information about the build? All cmake args you used, wxWidgets config shoudn't matter, gcc version. You build against an external lua 5.2 it looks like? Anything about that library? If you run ldd on the wxLua wx.so, it's using the right lua.so and the right lua #includes were used during compile (run $ make VERBOSE=1), etc...

    Thanks.

     
  • Matthias Mailänder

    Please not that using LUA_OK breaks Lua 5.1 compatibility. I changed it to 0 when applying the patch to https://build.opensuse.org/request/show/412755

     
  • Pavel Kulchenko

    Pavel Kulchenko - 2019-07-03

    I've applied this patch a several others to improve stability on exit. All these changes have been included in the latest release in https://github.com/pkulchenko/wxlua/.

     
  • Pavel Kulchenko

    Pavel Kulchenko - 2020-09-06
    • status: open --> closed-fixed
     

Log in to post a comment.