Page 1 of 1

_CrtSetBreakAlloc not working

Posted: Thu Aug 30, 2018 5:21 pm
by mael15
hi everyone,
i have a reproducible heap error that visual studio 2017 shows after my app has exited:
{5979} normal block at 0x02D553D8, 772 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
until now, _CrtSetBreakAlloc has showed me the problem, but unfortunately not anymore. i have 7 dlls and one exe, in each one i put _CrtSetBreakAlloc at the (in my opinion) earliest position.
AFAIK the heap error probaly occurs BEFORE i set _CrtSetBreakAlloc? So is there a way to know for sure the earliest possible position to put _CrtSetBreakAlloc? I have tested _CrtSetBreakAlloc successfully with some other allocation, so the mechanism itself works.
furthermore i tried:

Code: Select all

int YourAllocHook(int nAllocType, void *pvData,
	size_t nSize, int nBlockUse, long lRequest,
	const unsigned char * szFileName, int nLine) {

	if (nAllocType == _HOOK_ALLOC && nSize == 772)
		int breakHere = 0;

	if (nBlockUse == _CRT_BLOCK)
		return(TRUE);
	return true;
}
with the accompanying _CrtSetAllocHook(YourAllocHook) because the heap error has 772 bytes. Since this did not result in anything useful I guess this also might be invoked too late?
thank you for your thoughts.

Re: _CrtSetBreakAlloc not working

Posted: Fri Aug 31, 2018 1:15 am
by doublemax
Have you tried Visual Leak Detector?
https://kinddragon.github.io/vld/

Re: _CrtSetBreakAlloc not working

Posted: Fri Aug 31, 2018 9:55 am
by mael15
doublemax wrote:Have you tried Visual Leak Detector?
https://kinddragon.github.io/vld/
good idea, thanx! after adding vld.h to all my dlls and exe the error still does not get detected. does that mean it occurs in some other dll? of so, how can i find out which one?
No memory leaks detected.
Visual Leak Detector is now exiting.
Detected memory leaks!
Dumping objects ->
{7179} normal block at 0x001BD758, 128 bytes long.
Data: <x > 78 13 E7 05 80 13 E7 05 88 13 E7 05 90 13 E7 05
{5980} normal block at 0x00211570, 772 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{5979} normal block at 0x001C7238, 28 bytes long.
Data: <p ! > 70 15 21 00 C1 00 00 00 00 00 00 00 CD CD CD CD
Object dump complete.

Re: _CrtSetBreakAlloc not working

Posted: Fri Aug 31, 2018 10:40 am
by doublemax
Are these DLLs also written by you? If yes, try adding VLD to them, too.

Otherwise i can't think of any other way except disabling them one by one. Of course that's not always possible - or at least not easily.

Re: _CrtSetBreakAlloc not working

Posted: Fri Aug 31, 2018 10:48 am
by mael15
yes, these dlls are written by me and i have added vld to all of them. i also posted this on the vld github issues page: https://github.com/KindDragon/vld/issues/56. i really do not know what else i can do...

Re: _CrtSetBreakAlloc not working

Posted: Fri Aug 31, 2018 3:21 pm
by mael15
i am not sure if this is progress, but i got some output using gflags:
(232c.81c): Access violation - code c0000005 (first chance)
(232c.81c): Access violation - code c0000005 (!!! second chance !!!)
*** WARNING: Unable to verify checksum for C:\ecworks_mep\_BUILD\debug\wxbase311ud_vc_custom.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\ecworks_mep\_BUILD\debug\wxbase311ud_vc_custom.dll -
eax=1dffef90 ebx=00abf000 ecx=1dffef90 edx=5ac2111c esi=009ffaf4 edi=009ffc70
eip=5a2f995a esp=009ffaac ebp=009ffac4 iopl=0 nv up ei pl nz na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010206
wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x159e73:
5a2f995a 83780400 cmp dword ptr [eax+4],0 ds:002b:1dffef94=????????
0:000> .lines
Line number information will be loaded
0:000> kb
*** WARNING: Unable to verify checksum for C:\ecworks_mep\_BUILD\debug\wxbase311ud_vc_custom.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\ecworks_mep\_BUILD\debug\wxbase311ud_vc_custom.dll -
ChildEBP RetAddr Args to Child
WARNING: Stack unwind information not available. Following frames may be wrong.
009ffac4 5a2f9b12 08f4aff0 009ffaec 5a1bdd7e wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x159e73
009ffad0 5a1bdd7e 57742728 08f4aff0 009ffb24 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x15a02b
*** WARNING: Unable to verify checksum for C:\ecworks_mep\_BUILD\debug\wxmsw311ud_core_vc_custom.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\ecworks_mep\_BUILD\debug\wxmsw311ud_core_vc_custom.dll -
009ffaec 5a60519a 009ffb3c 08f4aff0 009ffb08 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x1e297
009ffafc 5a7154cf 08f4aff0 009ffb14 5a8c544f wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x4989f
009ffb08 5a8c544f 08f4aff0 009ffb30 5a613061 wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x159bd4
009ffb14 5a613061 fc4acc3a 08f4aff0 009ffc70 wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x309b54
009ffb30 5a959f79 00000001 009ffb64 cccccccc wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x57766
009ffb4c 5a959938 5aed9bd4 1c0fefd0 009ffb6c wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x39e67e
009ffb5c 5a24e03e 009ffb74 1c0fefd0 009ffc7c wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x39e03d
009ffb6c 5a2f4935 577421b8 009ffd74 009ffcb4 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0xae557
009ffc7c 5a24b28d 5a572d10 009ffcac 5a2d7263 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x154e4e
009ffc88 5a2d7263 009ffcb4 cccccccc cccccccc wxbase311ud_vc_custom!wxBaseArrayLong::Item+0xab7a6
009ffcac 5a2d66d4 009ffd14 1bb40e88 1bb40e88 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x13777c
009ffccc 5a2d6a52 57742134 cccccccc 5a5720f4 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x136bed
009ffcf0 5a22ef5c 577420c8 009ffd6f 009ffd78 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x136f6b
009ffd0c 5a2d7464 57742040 009ffeb8 009ffdd0 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x8f475
009ffd84 5a3b2efb 5aed942c 1bb3af78 57742004 wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x13797d
009ffdc0 5a921973 5aed942c 1bb3af78 009ffdec wxbase311ud_vc_custom!wxBaseArrayLong::Item+0x213414
*** WARNING: Unable to verify checksum for ecInspector.exe
009ffdd4 01509fa4 01390000 00000000 00000000 wxmsw311ud_core_vc_custom!wxTopLevelWindowMSW::SetLastFocus+0x366078
009ffeb8 01887a5e 01390000 00000000 00d3ffec ecInspector!WinMain+0x34 [c:\ecworks_mep\_winohnedll\src\app.cpp @ 141]
009ffed0 01887977 b6f3d677 01887ab0 01887ab0 ecInspector!invoke_main+0x1e [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 107]
009fff2c 0188781d 009fff3c 01887ab8 009fff50 ecInspector!__scrt_common_main_seh+0x157 [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
009fff34 01887ab8 009fff50 754f8484 00abf000 ecInspector!__scrt_common_main+0xd [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331]
009fff3c 754f8484 00abf000 754f8460 060a10b3 ecInspector!WinMainCRTStartup+0x8 [f:\dd\vctools\crt\vcstartup\src\startup\exe_winmain.cpp @ 17]
009fff50 77ae2fea 00abf000 5263d14e 00000000 KERNEL32!BaseThreadInitThunk+0x24
009fff98 77ae2fba ffffffff 77afec2a 00000000 ntdll!__RtlUserThreadStart+0x2f
009fffa8 00000000 01887ab0 00abf000 00000000 ntdll!_RtlUserThreadStart+0x1b
the line
ecInspector!WinMain+0x34 [c:\ecworks_mep\_winohnedll\src\app.cpp @ 141]
has my IMPLEMENT_APP(App) so not really anything that i have written myself. could this be the heap error and what could cause it?!
i recently switched to wxWidgets 3.1.1, maybe there is something wrong since it is still the development version?

Re: _CrtSetBreakAlloc not working

Posted: Tue Sep 04, 2018 3:21 pm
by mael15
okay, i can confirm that this heap error only occurs in wxWidgets 3.1.1 and not in 3.1.0 so i know it has nothing to do with my code. i will try and post this somewhere wxWidgets related.

Re: _CrtSetBreakAlloc not working

Posted: Tue Sep 04, 2018 3:40 pm
by doublemax
In that case i'd suggest a git bisect in order to find the code change in wxWidgets that caused it.

Re: _CrtSetBreakAlloc not working

Posted: Mon Sep 10, 2018 12:58 pm
by mael15
doublemax wrote:In that case i'd suggest a git bisect in order to find the code change in wxWidgets that caused it.
Thanx, unfortunately I do not have time to find the cause although I would want to help find it. I am happy with just switching back to 3.1.0.