I have a suite of tests written in C++/CLI that call into a native DLL in order to remotely test a Windows CE device. At two points during the test setup process, memory on the native heap is allocated--once for 512 bytes, the other for 572 bytes. In both instances, malloc() eventually called HeapAlloc() using the CRT heap. The handle to the CRT heap did not change between calls. The call that was meant to allocate 572 bytes fails with exception 0xc0000005 (I can try to provide code examples if need be, but will have to figure out what examples are generic enough not to break NDA).
Asked
Active
Viewed 839 times
1
-
2@ildjarn Disagree. Getting an access violation when trying to allocate memory is a common sign of something in your application/process that is overwriting something it shouldn't (e.g., write past end of allocated block, write to invalid pointer, freeing a block multiple times, etc.). – jdigital Jun 28 '11 at 23:28
-
I agree with @jdigital, specifically that allocations functions are likely to crash when *heap corruption* has occurred (and @jdigital has listed several possible causes). – Ben Voigt Jun 29 '11 at 00:10
-
(Repeating my question without the motivation since the motivation is getting more feedback than the question itself.) Can you reproduce this on a different machine, or is it only happening on one machine? – ildjarn Jun 29 '11 at 01:34
2 Answers
1
It looks like what finally solved the problem was not using the C Runtime heap, but using either GetProcessHeap() or a local heap to do the allocations.

Chris Meredith
- 21
- 3
-
1The program was compiled in debug mode, and for some reason HeapAlloc was causing the AV (which shouldn't happen). Writing my own wrappers around HeapAlloc() and HeapFree() seem to have stopped the crashes, though I lose a certain amount of debuggabilitay unless I want to write my own malloc tracking code, which would be a different bout of insomnia entirely. – Chris Meredith Jul 01 '11 at 02:43
0
Consider using a debugging malloc. Here's an article about using DevStudio debug mode in order to substitute special debugging versions of malloc and free.

jdigital
- 11,926
- 4
- 34
- 51