PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

_CrtIsValidHeapPointer(pUserData) in dbghelp.c

 
 
jiing
Guest
Posts: n/a
 
      30th Apr 2005
When I execute my program (it's multithread and has COM and dll),
there is an error message as follows:

Program D:\dongle_1\TestAP\bin\Debug\TestAP.exe
File: dbgheap.c
Line: 1132
Expression: _CrtIsValidHeapPointer(pUserData)
For information on how your program can cause an assertion failure, see
the Visual C++ documentation on asserts.
==================================================
I read the dbgheap.c and find the line 1132, it's as follows:
/*
* 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.
*/
1132: _ASSERTE(_CrtIsValidHeapPointer(pUserData));


=============================================================I also use
google to find some answers.
They said
(1) If you are developing multithread application, be sure to link it
with
the correct runtime library(/MD, /MT). That what
"The pointer MUST come from the 'local' heap." means.
Check what "ruintime library" you use. It should be "Multi threaded (
debug ) DLL"

Roman

(2)
Not only must they match, they must both be DLL versions. If they're
static versions, each piece (the exe and the dll) will have their own
heap and the OP will still be deleting from mismatched heaps.
I'd also be suspicious of general design issues given the way the OP's
main program is having to clean up for the dll.

You'll get this problem if you use two different run-time libraries,
one to
allocate the memory and one to de-allocate the memory. Open up the
project
settings dialog, switch to C/C++ tab, set Category to Code Generation
and
check the Use run-time library combo box. These must match in any
modules
that share the task of allocating and destroying memory.
--
Randy Charles Morin
Author of Programming Windows Services
http://www.kbcafe.com
=====================================================
If necessary, my dirty code is as follows (Please read from the bottom
up)
http://irc.csie.org:8888/125

Thanks in advance .

-jiing-

 
Reply With Quote
 
 
 
 
New Member
Join Date: Feb 2011
Posts: 2
 
      10th Feb 2011
Thanks for it. Point 2 worked for me.
 
Reply With Quote
 
New Member
Join Date: Mar 2012
Posts: 2
 
      25th Mar 2012
Hi,

I am also facing the same problem. What did you do to fix this issue? you said that the point second worked for you. I also did the first point setting up runtime library to /MD or /MDd. not working. second point not able understand clearly. Pls help me to resolve it.
.
Thanks
Rani

Last edited by Rani Manickam; 25th Mar 2012 at 07:16 PM..
 
Reply With Quote
 
New Member
Join Date: Feb 2011
Posts: 2
 
      26th Mar 2012
Open up the project settings dialog, switch to C/C++ tab, set Category to Code Generation and check the Use run-time library combo box. These must match in any modules.
 
Reply With Quote
 
New Member
Join Date: Mar 2012
Posts: 2
 
      3 Weeks Ago
Hi,

Sorry for late reply. I have checked all modules. it matching.

in my code, i am having below method.

Severity CMDIClass::BuildColumnMap(CMapStringToWord& mIndexMap)
{
int nIndex;
long retcode;
CS_DATAFMT datafmt;
char szColumnName[COLUMN_NAME_LENGTH];

Severity eReturnValue = NO_ERRORS;
TRY
{

retcode = ct_res_info(m_pCommand, CS_NUMDATA, &m_nNumberOfColumns, CS_UNUSED, NULL);


if (retcode != CS_SUCCEED)
{
/* Fix for contract to contract wizard error,
when we have multiple parts and choose part replacement */

//return FATAL_ERROR;
m_nNumberOfColumns = 0;
}

for(nIndex = 1;nIndex <= m_nNumberOfColumns; nIndex++)
{
/*
** Get the column name, then add the entry to the map using the column name
** as the key and storing the nIndex -1 as the value.
*/
retcode = ct_describe(m_pCommand, nIndex, &datafmt);
if (retcode != CS_SUCCEED)
{
return FATAL_ERROR;
}
#ifdef _WIN32
strncpy(szColumnName,datafmt.name,COLUMN_NAME_LENGTH); //for CTLib

#else
_fstrncpy((LPSTR) szColumnName,datafmt.name,COLUMN_NAME_LENGTH); // for CTLib
#endif
szColumnName[COLUMN_NAME_LENGTH] = '\0';
mIndexMap.SetAt(ColumnName, (WORD)(nIndex - 1));
}
}
CATCH(CException, exException)
{
eReturnValue = FATAL_ERROR;
}
END_CATCH
return eReturnValue;
}

it calls
mIndexMap.SetAt(ColumnName, (WORD)(nIndex - 1));

SetAt is inline function of CMapStringToWord class
AFXCOLL_INLINE void CMapStringToWord::SetAt(constchar* key, WORD newValue)
{ (*
this)[key] = newValue; }

it calls the below function.

WORD& CMapStringToWord::operator[](constchar* key)
{
const CString afxEmptyString;
ASSERT_VALID(
this);
UINT nHash;
CAssoc* pAssoc;
if ((pAssoc = GetAssocAt(key, nHash)) == NULL)
{
if (m_pHashTable == NULL)
InitHashTable(m_nHashTableSize);
// it doesn't exist, add a new Association
pAssoc = NewAssoc();
pAssoc->nHashValue = nHash;
pAssoc->key = key;
// 'pAssoc->value' is a constructed object, nothing more
// put into hash table
pAssoc->pNext = m_pHashTable[nHash];
m_pHashTable[nHash] = pAssoc;
}
return pAssoc->value; // return new reference
}
SetAt is called for 72 items. in that for 31 item SetAt is working fine. after that it goes to dbgheap.c

extern"C" _CRTIMP int__cdecl _CrtIsValidHeapPointer(
constvoid * pUserData
)
{
if (!pUserData)
return FALSE;
if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
return FALSE;
return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}

any problem in the code. Pls help me to identify the problem.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
_CrtIsValidHeapPointer exception Adriano Coser Microsoft VC .NET 4 31st Jul 2007 06:47 PM
_CrtIsValidHeapPointer =?Utf-8?B?SnNDaGFybHk=?= Microsoft VC .NET 3 24th May 2007 10:47 AM
_CrtIsValidHeapPointer and templates =?iso-8859-1?q?Erik_Wikstr=F6m?= Microsoft VC .NET 6 24th May 2007 02:54 AM
[help]_CrtIsValidHeapPointer(pUserData) in dbgheap.c jiing Microsoft VC .NET 0 30th Apr 2005 10:18 AM
SP4 and DBGHELP.DLL rob Microsoft Windows 2000 2 24th Aug 2003 07:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:18 PM.