lua-users home
lua-l archive

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


On Thursday 24 February 2005 17:07, Fabian Peña wrote:
> please see this C code
[...]
> Tthat it  happens to the memory assigned in strdup?   Memory Leak ?

Yes.

lua_pushstring takes its own copy of the string, which means that it's your 
responsibility to free the string returned by getSome() once you've done with 
it.

int tolua_getSome(lua_State* L)
{
 const char* s = getSome();
 lua_pushstring(L, s);
 free(s);
 return 1;
};

(BTW, I notice your code calls tolua_pushstring(), not lua_pushstring()... I 
don't know whether that's a typo or if you're using the tolua library, which 
I have no experience of. If so, tolua_pushstring() might have different 
semantics.)

-- 
"Curses! Foiled by the chilled dairy treats of righteousness!" --- Earthworm 
Jim (evil)