Click here to Skip to main content
16,003,345 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Socket send problem Pin
Mark Salsbery23-Aug-07 11:10
Mark Salsbery23-Aug-07 11:10 
GeneralRe: Socket send problem Pin
BakaBug24-Aug-07 0:19
BakaBug24-Aug-07 0:19 
GeneralRe: Socket send problem Pin
Mark Salsbery24-Aug-07 5:24
Mark Salsbery24-Aug-07 5:24 
GeneralRe: Socket send problem Pin
BakaBug27-Aug-07 5:58
BakaBug27-Aug-07 5:58 
GeneralRe: Socket send problem [modified] Pin
BakaBug29-Aug-07 1:49
BakaBug29-Aug-07 1:49 
QuestionSocket Problem Pin
GauranG Shah23-Aug-07 1:12
GauranG Shah23-Aug-07 1:12 
AnswerRe: Socket Problem Pin
BakaBug23-Aug-07 1:37
BakaBug23-Aug-07 1:37 
Questionheap corruption Pin
devvvy23-Aug-07 1:12
devvvy23-Aug-07 1:12 
Hi my pet program is crashing at "_ASSERTE(_CrtIsValidHeapPointer(pUserData))" ...

<br />
int main(int argc, char* argv[])<br />
{<br />
...<br />
char szBuffer1[10] = "abcde";<br />
char szBuffer2[10] = "fghij";<br />
char * pszBuffer = NULL;<br />
char ch;<br />
<br />
pszBuffer = new char[10];<br />
free(pszBuffer); << LOCATION1: OKAY<br />
pszBuffer = NULL;<br />
<br />
pszBuffer = CUtilities::NullTerminateString(szBuffer1); << From "Utilities" dll - i.e. different translation unit<br />
ch = pszBuffer[5]; // Should be '\0'<br />
free(pszBuffer); << LOCATION2: CRASH Here!<br />
pszBuffer = NULL;<br />
...<br />
}


It crashed at LOCATION1.

Looking into "Utilities" dll, looks like memory is allocated the very same way as "pszBuffer = new char[10]" - what makes the difference between LOCATION1 and LOCATION2:
char * CUtilities::NullTerminateString(char * pszData)<br />
{<br />
	char * pszResult = NULL;<br />
<br />
	if(pszData==NULL)<br />
	{<br />
		return NULL;<br />
	}<br />
<br />
	string strTemp(pszData);<br />
	int nSize = strTemp.size() +1;<br />
<br />
	pszResult = new char[nSize];<br />
	strcpy(pszResult, pszData);<br />
	pszResult[nSize-1] = '\0';<br />
<br />
	return pszResult;<br />
}


The only difference it seems is that LOCATION1 is in "main" and LOCATION2 is in "Utilities" dll, is that significant?

Stack trace lead us to here:
_CRTIMP void __cdecl _free_dbg(<br />
        void * pUserData,<br />
        int nBlockUse<br />
        )<br />
{<br />
 ...<br />
        /*<br />
         * If this ASSERT fails, a bad pointer has been passed in. It may be<br />
         * totally bogus, or it may have been allocated from another heap.<br />
         * The pointer MUST come from the 'local' heap.<br />
         */<br />
        _ASSERTE(_CrtIsValidHeapPointer(pUserData)); << CRASH HERE!<br />
<br />
...<br />
}


Thanks
AnswerRe: heap corruption Pin
jhwurmbach23-Aug-07 1:22
jhwurmbach23-Aug-07 1:22 
Generaldifferent dll - must use SysAllocString and SysFreeString? Pin
devvvy23-Aug-07 14:01
devvvy23-Aug-07 14:01 
GeneralRe: different dll - must use SysAllocString and SysFreeString? Pin
jhwurmbach23-Aug-07 21:37
jhwurmbach23-Aug-07 21:37 
AnswerRe: heap corruption Pin
Iain Clarke, Warrior Programmer23-Aug-07 1:33
Iain Clarke, Warrior Programmer23-Aug-07 1:33 
GeneralRe: heap corruption Pin
Russell'23-Aug-07 1:49
Russell'23-Aug-07 1:49 
GeneralRe: heap corruption Pin
devvvy23-Aug-07 13:51
devvvy23-Aug-07 13:51 
GeneralRe: heap corruption Pin
Iain Clarke, Warrior Programmer23-Aug-07 21:54
Iain Clarke, Warrior Programmer23-Aug-07 21:54 
GeneralRe: heap corruption Pin
devvvy29-Aug-07 2:58
devvvy29-Aug-07 2:58 
AnswerRe: heap corruption Pin
ghle27-Aug-07 4:24
ghle27-Aug-07 4:24 
GeneralRe: heap corruption Pin
devvvy29-Aug-07 2:57
devvvy29-Aug-07 2:57 
QuestionSmall question Pin
Chen-XuNuo22-Aug-07 23:01
Chen-XuNuo22-Aug-07 23:01 
AnswerRe: Small question Pin
fefe.wyx22-Aug-07 23:12
fefe.wyx22-Aug-07 23:12 
AnswerRe: Small question Pin
toxcct22-Aug-07 23:17
toxcct22-Aug-07 23:17 
AnswerRe: Small question Pin
Roger Broomfield22-Aug-07 23:20
Roger Broomfield22-Aug-07 23:20 
JokeRe: Small question Pin
Cedric Moonen22-Aug-07 23:22
Cedric Moonen22-Aug-07 23:22 
GeneralRe: Small question Pin
toxcct22-Aug-07 23:25
toxcct22-Aug-07 23:25 
GeneralRe: Small question Pin
Roger Broomfield22-Aug-07 23:32
Roger Broomfield22-Aug-07 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.