lua-users home
lua-l archive

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


When running valgrind on the two functions below, I get the following errors:


16 bytes in 1 blocks are still reachable in loss record 2 of 6
at 0x1B903043: operator new(unsigned) (vg_replace_malloc.c:133)
by 0x805194F: LuaWrapper::create_Wrapper(lua_State*) (luawrapper.cpp:23)
by 0x8059E3A: luaD_precall (in /home/groleo/code/balu/balu)
by 0x80621C6: luaV_execute (in /home/groleo/code/balu/balu)

Which refer to the pointer a.

Question:
does the lua_unboxpointer frees the "a" pointer? 
I dont want to get ugly mem leaks.




Wrapper*
LuaWrapper::checkWrapper( lua_State* L, int narg)
{
     luaL_checktype( L, narg, LUA_TUSERDATA);
     void* ud =luaL_checkudata( L, narg, className);
     if( ! ud)
          luaL_typerror( L, narg, className);
     return *( Wrapper**) ud;                 // unbox pointer
}




int
LuaWrapper::create_Wrapper( lua_State *L)
{
     string host =luaL_check_string( L, 1);
     int port =( int)luaL_checknumber( L,2 );
     Wrapper* a =new Wrapper( host, port);
     lua_boxpointer( L, a);//Box Pointer?
     luaL_getmetatable( L, className);//get meta table?
     lua_setmetatable( L, -2);// set metatable?
     return 1;
}



-- 
Regards, Groleo!

# touch universe
# chmod +rwx universe
# ./universe