_CrtIsValidHeapPointer( pUserData )

_CrtIsValidHeapPointer( pUserData )

Hi ya, I have integrated the SDK, its all working fine when I run it in Visual Studio BUT when I build the release version into the MSI installer and run the app then I get an assertion error and this message... _CrtIsValidHeapPointer(pUserData) Normally I would put it down to a character array running over but I don't get this error in visual studio, it runs fine. If I try to debug the exe in visual studio then visual studio just crashes. Also when I try to run the exe from the output folder that visual studio creates when it does a local build I get the same error. I have multiple versions of our app that all install and run fine. The only difference with this one is that in order to get the SDK working I had to use the the linked runtime DLL (/MD) rather than (/MT) and I've also generated the manifest rather than embed it. This is the first time I have built a project this way so I may have done something really stupid. Any help would be appreciated, this is the last hurdle before I can submit it. Thanks in advanced, Andy
6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

I am migrating my application which was developed in VC++ 6.0 to VS2010. The application has one exe and dlls. all the DLLs are linked statically. Now it throws exception in the below code.

* * If this ASSERT fails, a bad pointer has been passed in. It may be * totally bogus, or it may have been allocated from another heap. * The pointer MUST come from the 'local' heap.
*/ _ASSERTE(_CrtIsValidHeapPointer(pUserData));

In my output window I am having the below message
Initializing GPSMGR.DLL from C:\APPS\GPS\GPS1200\Gps32d.exe HEAP[Gps32d.exe]: Invalid Address specified to RtlValidateHeap( 00B50000, 7907CD38 ) Windows has triggered a breakpoint in Gps32d.exe. This may be due to a corruption of the heap, which indicates a bug in Gps32d.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while Gps32d.exe has focus. The output window may have more diagnostic information. 'Gps32d.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime', Symbols loaded (source information stripped). Gps32d.exe has triggered a breakpoint

My stack is looking like below

msvcr100d.dll!realloc_help(void * pUserData, unsigned int * pnNewSize, int nBlockUse, const char * szFileName, int nLine, int fRealloc) Line 793 + 0x30 bytes C++
msvcr100d.dll!_realloc_dbg(void * pUserData, unsigned int nNewSize, int nBlockUse, const char * szFileName, int nLine) Line 1040 + 0x1b bytes C++
mfc100d.dll!CAfxStringMgr::Reallocate(ATL::CStringData * pData, int nChars, int nCharSize) Line 188 + 0x1a bytes C++
mfc100d.dll!ATL::CSimpleStringT::Reallocate(int nLength) Line 881 + 0x17 bytes C++
mfc100d.dll!ATL::CSimpleStringT::PrepareWrite2(int nLength) Line 870 C++
mfc100d.dll!ATL::CSimpleStringT::PrepareWrite(int nLength) Line 838 C++
mfc100d.dll!ATL::CSimpleStringT::GetBuffer(int nMinBufferLength) Line 535 C++
mfc100d.dll!ATL::CSimpleStringT::SetString(const char * pszSrc, int nLength) Line 654 + 0xc bytes C++
mfc100d.dll!ATL::CSimpleStringT::SetString(const char * pszSrc) Line 629 C++
mfc100d.dll!ATL::CSimpleStringT::operator=(const char * pszSrc) Line 342 C++
mfc100d.dll!ATL::CStringT > >::operator=(const char * pszSrc) Line 1235 C++
gpssc32d.dll!CMapStringToWord::operator[](const char * key) Line 277 C++
gpssc32d.dll!CMapStringToWord::SetAt(const char * key, unsigned short newValue) Line 123 + 0x13 bytes C++
GpsCt32d.Dll!CGpsInit::LoadOneName2Maps(const char * lpszColName, int nFillType, int fValueMap) Line 389 C++
GpsCt32d.Dll!CGpsInit::LoadColName2Maps() Line 147 + 0x12 bytes C++ GpsCt32d.Dll!CGpsInit::Initialize() Line 329 + 0x5 bytes C++
GpsMg32D.dll!InitGpsMgrDll(HINSTANCE__ * hInstance) Line 236 C++
Gps32d.exe!0040bb86()
[Frames below may be incorrect and/or missing, no symbols loaded for Gps32d.exe]
ntdll.dll!_NtQueryDebugFilterState@8() + 0xc bytes
ntdll.dll!_vDbgPrintExWithPrefix@20() + 0x43 bytes
ntdll.dll!_RtlAllocateHeapSlowly@12() + 0x3da bytes

I searched in the google that the c runtime in property page should be /MD or /MDd. i did it. but still i am facing the problem once it reaches to the below code in my application.

AFXCOLL_INLINE void CMapStringToWord::SetAt(LPCTSTR key, WORD newValue) { (*this)[key] = newValue; }

I am not facing in release mode.

Pls help me to resolve it.

Thanks
Rani

Andy,

This is happening because you are allocating memory in one heap and deleting it in another heap. The cause? You are mixing static and dll references of the CRT runtime (/MD and /MT).

If you change everything to use /MT this issue will go away.

Andy,

Just a quick follow up. I re-created the same scenario as you are in, and confirmed the reply above. Please let me know if you have any trouble. Best of luck.

Thanks Brian,

Once again you have solved my problem :)

It actually wasn't what you said but it gave me a rather large clue. We have a small in house 'game engine' which is linked in via libraries, they weren't linked as static which was obviously the conflict. I can't actually change the CRT runtime linkage switches from /MD to /MT because having them static linked solved my previous problem which you helped me solve. Anyway, its all working now and thanks once again.

Andy

No problem, I look forward to seeing your entry in AppUp.

Leave a Comment

Please sign in to add a comment. Not a member? Join today