My project uses wxWidgets as a monolithic shared library. Another shared library in the project provides a global allocator new/delete. If I modify the allocation size to allow library data overhead with every allocation, wxWidgets eventually fails with some kind of memory error.
In every case, it seems that somehow the system is calling my operator delete from the _CFRelease related to something about changing the menu. It seems that the system is passing me a handle to some old menu data that was not allocated by my global operator new, but gets sent to my global operator delete, which causes problems.
Here's a sample stack trace, though the specific call from my code that triggers the problem can depend on what I do exactly during my startup code:
Code: Select all
#0 0x919844a9 in malloc_error_break
#1 0x9197f497 in szone_error
#2 0x918a9503 in szone_free
#3 0x918a936d in free
// --- Calls free, and ends up in error
#4 0x01813688 in _DoFree at Memory.cpp:429
#5 0x01813728 in operator delete at Memory.cpp:485
// --- My operator delete
#6 0x970af768 in HIObject::HandleClassHIObjectEvent
#7 0x970af5d3 in HIObject::EventHook
#8 0x970af13d in DispatchEventToHandlers
#9 0x970ae57b in SendEventToEventTargetInternal
#10 0x970ae3e0 in SendEventToEventTargetWithOptions
#11 0x970ede22 in HIObject::Destruct
#12 0x94a0f516 in _CFRelease
#13 0x972007e2 in MenuData::~MenuData
#14 0x970af768 in HIObject::HandleClassHIObjectEvent
#15 0x970af5d3 in HIObject::EventHook
#16 0x970af13d in DispatchEventToHandlers
#17 0x970ae57b in SendEventToEventTargetInternal
#18 0x970ae3e0 in SendEventToEventTargetWithOptions
#19 0x970ede22 in HIObject::Destruct
#20 0x94a0f516 in _CFRelease
#21 0x9712ddfa in ReleaseMenu
#22 0x9712cf5e in SystemAppMenuHandler
#23 0x970af13d in DispatchEventToHandlers
#24 0x970ae57b in SendEventToEventTargetInternal
#25 0x970ae3e0 in SendEventToEventTargetWithOptions
#26 0x970fb853 in PopulateMenu
#27 0x970fb492 in FindItemByCommand
#28 0x970fb68b in FindItemByCommand
#29 0x970fb344 in _GetIndMenuItemWithCommandID
#30 0x9719177f in DisableMenuCommand
// --- system code
#31 0x00d01493 in wxMenuBar::MacInstallMenuBar
#32 0x00cdf25e in wxFrame::AttachMenuBar
#33 0x00da7411 in wxFrameBase::SetMenuBar
#34 0x0010e789 in MainWindow::BuildMenus at MainWindow.cpp:253
#35 0x0010f102 in MainWindow::MainWindow at MainWindow.cpp:207
#36 0x0018a253 in MyApp::OnAppStartupEvt at MyApp.cpp:302
// ... more init methods in my code
#45 0x00509d7b in wxMyApp::OnInit at wxMyApp.cpp:121
#46 0x0018b26a in wxAppConsole::CallOnInit at app.h:76
#47 0x00c2399e in wxEntry
#48 0x0018b1f4 in main at MyApp.cpp:70
#49 0x000028d6 in start
Code: Select all
// because malloc allocates memory aligned on a 16 byte boundary
// if this block is not misaligned exactly as expected
if( reinterpret_cast< unsigned int >( obj ) % 16 == 0 )
{
// just free and return
free( obj );
return;
}
I normally compile as a Universal binary for 10.4 and later (32 bit of course). The only other similar case I have found was with a different library. On this link, someone else had the same issue with a different library:
http://www.bannister.org/forums/ubbthre ... 173&page=3
The problem happens at the same point in that MenuData destructor. On advice from that post, I tried building both wxWidgets and my system using gcc-4.2 for the 10.5 SDK, but that didn't help.
Any ideas?
Thanks
-robin