Click here to Skip to main content
15,915,324 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: 2 MFC Questions from a newbie. Help please. Pin
Member 148206230-Oct-04 5:04
Member 148206230-Oct-04 5:04 
GeneralRe: 2 MFC Questions from a newbie. Help please. Pin
Natural_Demon31-Oct-04 5:02
Natural_Demon31-Oct-04 5:02 
GeneralRe: 2 MFC Questions from a newbie. Help please. Pin
31-Oct-04 10:50
suss31-Oct-04 10:50 
GeneralRe: 2 MFC Questions from a newbie. Help please. Pin
Natural_Demon31-Oct-04 10:59
Natural_Demon31-Oct-04 10:59 
GeneralEdge Linking Algorithm Pin
gilazilla30-Oct-04 5:01
gilazilla30-Oct-04 5:01 
Generaldebugging dll's Pin
ddskid30-Oct-04 3:53
ddskid30-Oct-04 3:53 
GeneralRe: debugging dll's Pin
Member 148206231-Oct-04 11:31
Member 148206231-Oct-04 11:31 
QuestionMemory Leak...Any Help ? Pin
Amarelia30-Oct-04 1:10
Amarelia30-Oct-04 1:10 
HI
I have a memory leak in my programm. I have tried hard but not been able to solve it. I m putting the whole code that is causing memory leak. Can you show me some idea where is the possibility of memory leak.????
My code goes here....
------------------------------------------
// File matools.cpp
typedef unsigned char Byte;
typedef unsigned int uInt;
typedef unsigned long uLong;

int CompressData (char* sIn, char* sKey, char** sOut, long* lOutlen)
{
Byte *compr, *uncompr;
uLong comprLen = 16384*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;

if (zlibVersion()[0] != myVersion[0])
return -1;

compr = (Byte*) new uInt[comprLen];
uncompr = (Byte*) new uInt[uncomprLen];
//End lines by Mahesh

if (compr == Z_NULL || uncompr == Z_NULL)
{
// Line added by Mahesh
//What if compr is NULL and uncompr is not NULL....no indication for it....
delete [] compr; //free(compr);
delete [] uncompr; //free(uncompr);
// End of line added by Mahesh
return -2;
}
uncomprLen = strlen (sIn);

int iResult = test_compress(compr, &comprLen, (Bytef*)sIn, uncomprLen);

if (iResult != 0)
{
// Line added by Mahesh
//What if compr is NULL and uncompr is not NULL....no indication for it....
uncomprLen = 0;
delete [] compr; //free(compr);
delete [] uncompr; //free(uncompr);
// End of line added by Mahesh
return -3;
}

byte *buffer, key[32];
unsigned int bufLen;
unsigned int err;
ailaes demo;
char s2[33] = "";

int len = strlen(sKey);
if (len > 64)
len = 64;

for (int i = 0, j = 0; i < len; i ++, j ++)
{
char sTemp[2] = "";

sTemp[0] = sKey[i];
sTemp[1] = 0;

int c = 0;
if (!stricmp(sTemp, "0") || !stricmp(sTemp, "1") || !stricmp(sTemp, "2") || !stricmp(sTemp, "3") || !stricmp(sTemp, "4") || !stricmp(sTemp, "5") || !stricmp(sTemp, "6") || !stricmp(sTemp, "7") || !stricmp(sTemp, "8") || !stricmp(sTemp, "9"))
c = atol(sTemp) * 16;
else if (!stricmp(sTemp, "A") || !stricmp(sTemp, "a"))
c = 10 * 16;
else if (!stricmp(sTemp, "B") || !stricmp(sTemp, "b"))
c = 11 * 16;
else if (!stricmp(sTemp, "C") || !stricmp(sTemp, "c"))
c = 12 * 16;
else if (!stricmp(sTemp, "D") || !stricmp(sTemp, "d"))
c = 13 * 16;
else if (!stricmp(sTemp, "E") || !stricmp(sTemp, "e"))
c = 14 * 16;
else if (!stricmp(sTemp, "F") || !stricmp(sTemp, "f"))
c = 15 * 16;

sTemp[0] = sKey[i + 1];
sTemp[1] = 0;
i ++;
if (!stricmp(sTemp, "0") || !stricmp(sTemp, "1") || !stricmp(sTemp, "2") || !stricmp(sTemp, "3") || !stricmp(sTemp, "4") || !stricmp(sTemp, "5") || !stricmp(sTemp, "6") || !stricmp(sTemp, "7") || !stricmp(sTemp, "8") || !stricmp(sTemp, "9"))
c += atol(sTemp);
else if (!stricmp(sTemp, "A") || !stricmp(sTemp, "a"))
c += 10;
else if (!stricmp(sTemp, "B") || !stricmp(sTemp, "b"))
c += 11;
else if (!stricmp(sTemp, "C") || !stricmp(sTemp, "c"))
c += 12;
else if (!stricmp(sTemp, "D") || !stricmp(sTemp, "d"))
c += 13;
else if (!stricmp(sTemp, "E") || !stricmp(sTemp, "e"))
c += 14;
else if (!stricmp(sTemp, "F") || !stricmp(sTemp, "f"))
c += 15;

s2[j] = c;
}
s2[j] = 0;


// pad out the input string to be an even block size

// Line Added My Mahesh Amarelia 02/09/04
// Memory allocated to the variable "*b" in strToBlock() has not been freed...
err = demo.strToBlock((char*)compr, comprLen, &buffer, &bufLen);

memmove(key, s2, 32);
demo.init(CBC, key);

// encript the buffer
err = demo.encrypt(buffer, bufLen);

if (err != 0)
{
// Line added by Mahesh
//What if compr is NULL and uncompr is not NULL....no indication for it....
uncomprLen = 0;
free (buffer);
delete [] compr; //free(compr);
delete [] uncompr; //free(uncompr);

// End of line added by Mahesh
return -4;
}

// encode the crypto buffer so it can pass as a null terminated string

*sOut = ESCencode( (char*)buffer, bufLen);

*lOutlen = strlen(*sOut);

//Lines added by Mahesh

delete [] buffer;
delete [] compr;
delete [] uncompr;

buffer = NULL;
compr = NULL;
uncompr = NULL;

return 1;
}

static char* ESCencode(char* sIn, long sLen)
{
char* sOut, *s;
long i,j, len, grow;
char c;

// determine len of encoded str
len = sLen;
for(i=0, s=sIn, grow=0; i<len; i++, s++)
if(*s == ESC || *s == ZERO || *s == 0x0d) //<<< new stuff here
grow++;

// len += (2 * grow);
len += grow;
// <AES_Encode> </AES_Encode>


/*****************************************/
/********* this is line number 309 ******/
sOut = new char[len + 1 + 25]; // Here sOut is not been freed after allocating memory

sOut[0] = '<';
sOut[1] = 'A';
sOut[2] = 'E';
sOut[3] = 'S';
sOut[4] = '_';
sOut[5] = 'E';
sOut[6] = 'n';
sOut[7] = 'c';
sOut[8] = 'o';
sOut[9] = 'd';
sOut[10] = 'e';
sOut[11] = '>';

for(i=0, j=12; j<(len + 12); i++)
switch(c = sIn[i]){
case NULL:
sOut[j++] = ZERO;
break;
case 0x0d: //<<< new stuff here
sOut[j++] = ESC;
sOut[j++] = mCR;
break;
case ZERO:
case ESC:
///Insert:
sOut[j++] = ESC;
// fall thru intended
default:
sOut[j++] = c;
break;
}
sOut[j++] = '<';
sOut[j++] = '/';
sOut[j++] = 'A';
sOut[j++] = 'E';
sOut[j++] = 'S';
sOut[j++] = '_';
sOut[j++] = 'E';
sOut[j++] = 'n';
sOut[j++] = 'c';
sOut[j++] = 'o';
sOut[j++] = 'd';
sOut[j++] = 'e';
sOut[j++] = '>';
// make sure it is null terminated
sOut[j++] = NULL;

return sOut;
}

The output that I get I use _CrtDumpMemoryLeaks() functions is as following :
-----------------------------------------------------------------------------
Detected memory leaks!
Dumping objects ->
c:\temp\matools\matools.cpp(310) : {58} normal block at 0x009F0530, 1095 bytes long.
Data: <<AES_Encode>j[L > 3C 41 45 53 5F 45 6E 63 6F 64 65 3E 6A 5B 4C F9
{46} normal block at 0x00861E20, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{45} normal block at 0x00861E70, 40 bytes long.
Data: < K > D0 10 4B 00 19 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
--------------------

Mike
AnswerRe: Memory Leak...Any Help ? Pin
BeerFizz30-Oct-04 5:48
BeerFizz30-Oct-04 5:48 
GeneralRe: Memory Leak...Any Help ? Pin
Amarelia31-Oct-04 17:47
Amarelia31-Oct-04 17:47 
GeneralRe: Memory Leak...Any Help ? Pin
Roger Allen1-Nov-04 3:13
Roger Allen1-Nov-04 3:13 
QuestionHow to get licence key for IBM's Rational Purify Evaluation ? Pin
Anonymous29-Oct-04 23:45
Anonymous29-Oct-04 23:45 
AnswerRe: How to get licence key for IBM's Rational Purify Evaluation ? Pin
Sujan Christo29-Oct-04 23:51
Sujan Christo29-Oct-04 23:51 
GeneralDeutsches Diskussion-Board gesucht! Pin
gerspeece29-Oct-04 23:43
gerspeece29-Oct-04 23:43 
GeneralRe: Deutsches Diskussion-Board gesucht! Pin
peterchen30-Oct-04 1:53
peterchen30-Oct-04 1:53 
GeneralDLL Info &amp;Frage Pin
gerspeece29-Oct-04 23:42
gerspeece29-Oct-04 23:42 
GeneralHi Pin
Rassul Yunussov29-Oct-04 22:47
Rassul Yunussov29-Oct-04 22:47 
GeneralSQL Server - Stored procedure Pin
Sujan Christo29-Oct-04 21:47
Sujan Christo29-Oct-04 21:47 
GeneralRe: SQL Server - Stored procedure Pin
Tim Smith31-Oct-04 8:55
Tim Smith31-Oct-04 8:55 
GeneralRe: SQL Server - Stored procedure Pin
Sujan Christo31-Oct-04 18:08
Sujan Christo31-Oct-04 18:08 
GeneralCheck mail and download attachments. Pin
.NetRams29-Oct-04 20:51
.NetRams29-Oct-04 20:51 
GeneralRe: Check mail and download attachments. Pin
ThatsAlok29-Oct-04 21:34
ThatsAlok29-Oct-04 21:34 
GeneralRe: Check mail and download attachments. Pin
Sujan Christo29-Oct-04 21:37
Sujan Christo29-Oct-04 21:37 
GeneralRe: Check mail and download attachments. Pin
.NetRams29-Oct-04 23:50
.NetRams29-Oct-04 23:50 
GeneralRe: Check mail and download attachments. Pin
Sujan Christo30-Oct-04 0:23
Sujan Christo30-Oct-04 0:23 

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.