gengyong/luaaa

new assertion in LuaClass constructor incompatible with unit testing

mck1117 opened this issue · 3 comments

This code will cause an assertion failure on the second test:

void test1()
{
	lua_State* l = make_lua();
	LuaClass<MyType> myLuaType(l, "MyType");

	// ... do stuff ...

	destroy_lua(l);
}

void test2()
{
	lua_State* l = make_lua();
	LuaClass<MyType> myLuaType(l, "MyType");

	// ... do stuff ...

	destroy_lua(l);
}

The assertion in the LuaClass constructor is currently too strict. Seeing if the same string is already there would likely be more appropriate.

please pull the newest version.
in new versions, lua class name was stored in lua userdata, and it will be clean in GC.

It gets better: if the runtime assertion fails (ie, not the assert, but the luaL_argcheck), it causes a use-after-free:

image

It looks like the Lua destructor function (line 678-681) is never called, so the pointer klassName is never cleared, causing the assertion failures.