Article ID: 190531
Article Last Modified on 2/24/2004
void __cdecl free(void* p)
{
#ifndef _ATL_NO_MP_HEAP
if (_Module.m_phHeaps == NULL)
#endif
HeapFree(_Module.m_hHeap, 0, p);
#ifndef _ATL_NO_MP_HEAP
else
{
HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
HeapFree(*pHeap, 0, pHeap);
}
#endif
}
There is no code here that checks if "p" is NULL; therefore, so HeapFree()
is called with an invalid handle.
void __cdecl free(void* p)
{
if (p == NULL) // Add this line.
return; // Add this line.
#ifndef _ATL_NO_MP_HEAP
if (_Module.m_phHeaps == NULL)
#endif
HeapFree(_Module.m_hHeap, 0, p);
#ifndef _ATL_NO_MP_HEAP
else
{
HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
HeapFree(*pHeap, 0, pHeap);
}
#endif
}
Another option to resolve this problem is to #define _ATL_NO_MP_HEAP. This
prevents the problematic code from being included. However, this does turn
off the optimization that ATL adds for multi-processor machines. You have
only one heap regardless of the number of processors. Heap access may be
less than optimal because access from multiple threads is serialized.
Additional query words: unhandled exception new malloc memory
Keywords: kbbug kbfix kbcrt kbvs600sp3fix KB190531