lua-users home
lua-l archive

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


Hi again,

I can reproduce the error with this code:

in my c file:

static int pf_debug1(lua_State *L) {
  lua_newtable(L);
  return 1;
}


in my unit test:

function tc:test_t1()
  libpathfind.pf_debug1()
end

Always causes the non-aligned pointer error. When I remove the lua_newtable(L) call the error goes away. Can anyone give me some insight into how Lua allocates tables and what might be causing this?

When I run the program in gdb the stack always shows that the free calls are coming from a garbage collection cycle (which I guess makes sense).

I'm running 10.5 (although the problem has occurred on 10.4 as well.) On a MacBook Pro Intel Core Duo.

Any help at all would be appreciated since it really doesn't look like it's in my code.


On 16/01/2008, at 5:28 PM, Rob Barris wrote:

On OS X all calls to malloc() will return something aligned in 16 byte boundary unless its size is less than 16 bytes or maybe 8 bytes.

So, the runtime is trying to let us know that some code path is possibly freeing a bogus pointer. Frame #4 in your crawl shows the point in Lua code where the call to free() is made.. I wonder if you have found a bug.


On Jan 15, 2008, at 5:35 PM, Scott Weeks wrote:

Hello,

I'm new here :-)

Anyway, I've been doing some development with Lua and OS X and have noticed that when I use some C libraries I get the following error (or something like it)

lua(8680) malloc: *** error for object 0x40fa4: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug

This has occured for me with the luasqlite3 library as well as with a C module that I've been writing. It occurs for me when I create a new table from within C.

Adding a lua_newtable(L) call or a luaL_newmetatable(L,"blah") call will get me these errors and they stop when I comment them out.

Now, I am very much a novice when it comes to C and memory management and am particularly baffled with things like pointer alignement, etc... I fired up gdb and managed to get the following stack when I ran my program with malloc_error_break set

Breakpoint 1, 0x94e9b9f1 in malloc_error_break ()
(gdb) where
#0  0x94e9b9f1 in malloc_error_break ()
#1  0x94e969df in szone_error ()
#2  0x94dbbb83 in szone_free ()
#3  0x94dbb9ed in free ()
#4  0x00015c94 in l_alloc ()
#5  0x0000c4fc in luaM_realloc_ ()
#6  0x00010a3b in luaH_free ()
#7  0x0000a71d in sweeplist ()
#8  0x0000ab4f in singlestep ()
#9  0x0000ae68 in luaC_step ()
#10 0x000140ea in luaV_execute ()
#11 0x00008e30 in luaD_call ()
#12 0x00004951 in f_call ()
#13 0x0000833b in luaD_rawrunprotected ()
#14 0x00009152 in luaD_pcall ()
#15 0x000049c5 in lua_pcall ()
#16 0x00016ffa in luaB_xpcall ()
#17 0x000089f3 in luaD_precall ()
#18 0x00013e9e in luaV_execute ()
#19 0x00008e30 in luaD_call ()
#20 0x00004951 in f_call ()
#21 0x0000833b in luaD_rawrunprotected ()
#22 0x00009152 in luaD_pcall ()
#23 0x000049c5 in lua_pcall ()
#24 0x00002833 in docall ()
#25 0x00003024 in pmain ()
#26 0x000089f3 in luaD_precall ()
#27 0x00008dd3 in luaD_call ()
#28 0x00004a90 in f_Ccall ()
#29 0x0000833b in luaD_rawrunprotected ()
#30 0x00009152 in luaD_pcall ()
#31 0x00004ae7 in lua_cpcall ()
#32 0x00003405 in main ()


I don't know if that's useful but it seems to be right around the palce where lua is reallocating memory... Any pointers would be greatly appreciated.

Cheers,
Scotty Weeks