Original Post
I'm working on an engine with lua integrated. I have several classes bound to lua with luabind. If i instantiate only one of these classes from lua, and then shut down the engine, everything is fine. But if I create more than one, when lua_closeis called on the engine shutdown, I get the following error:
The thread 'Win32 Thread' (0x910) has exited with code 0 (0x0).
HEAP[AACRead.exe]: HEAP: Free Heap block 11b1ca8 modified at 11b1cdc after it was freed
Windows has triggered a breakpoint in AACRead.exe.
This may be due to a corruption of the heap, and indicates a bug in AACRead.exe or any of the DLLs it has loaded.
the stack trace is as follows:
ntdll.dll!DbgBreakPoint()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!RtlpNtMakeTemporaryKey() + 0x6737 bytes
ntdll.dll!RtlInitializeSListHead() + 0x10b69 bytes
ntdll.dll!iswdigit() + 0x224 bytes
ntdll.dll!RtlpNtMakeTemporaryKey() + 0x7e56 bytes
ntdll.dll!RtlInitializeSListHead() + 0x115c0 bytes
ntdll.dll!iswdigit() + 0x128 bytes
AACRead.exe!_free_base(void * pBlock=0x011b1be0) Line 109 + 0x12 bytes C
AACRead.exe!_free_dbg_nolock(void * pUserData=0x011b1c00, int nBlockUse=0x00000001) Line 1224 + 0x9 bytes C++
AACRead.exe!_free_dbg(void * pUserData=0x011b1c00, int nBlockUse=0x00000001) Line 1089 + 0xd bytes C++
AACRead.exe!free(void * pUserData=0x011b1c00) Line 1047 + 0xb bytes C++
> AACRead.exe!luaM_realloc(lua_State * L=0x00ef61c8, void * block=0x011b1c00, unsigned long oldsize=0x00000024, unsigned long size=0x00000000) Line 69 + 0x9 bytes C
AACRead.exe!luaF_freeproto(lua_State * L=0x00ef61c8, Proto * f=0x011aa560) Line 103 + 0x1c bytes C
AACRead.exe!freeobj(lua_State * L=0x00ef61c8, GCObject * o=0x011aa560) Line 345 + 0xd bytes C
AACRead.exe!sweeplist(lua_State * L=0x00ef61c8, GCObject * * p=0x00ef6274, int limit=0x00000100) Line 378 + 0xd bytes C
AACRead.exe!luaC_sweep(lua_State * L=0x00ef61c8, int all=0x00000100) Line 442 + 0x17 bytes C
AACRead.exe!close_state(lua_State * L=0x00ef61c8) Line 147 + 0xb bytes C
AACRead.exe!lua_close(lua_State * L=0x00ef61c8) Line 218 + 0x9 bytes C
The C++ destructors for the created classes are being called, and completing correctly. I think lua or luabind is trying to free memory already freed, but why/how/where? and how do I fix it!?? I'm stumped.