the codeguard of my project can't catch memory leak

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

the codeguard of my project can't catch memory leak

Postby rui song » Mon Aug 24, 2015 10:30 am

i have an old project build with BCB6.

now ,i enable the codeguard opiton for it, and make a memory leak in the construct function of the mainform.

just like this:

char* buf = new char[10];

rebuild and run the application ,then close the mainform.

the codeguard can't catch the memory leak that i made.

but, i creat a new project with bcb6, enable the codeguard too, made the same memory leak

the codeguard of new project could catch it.

what 's wrong with the codeguard of the old project? lib? or others? how can i make it work in old project?

i had use tdump to check them both

the old project like this:

Imports from CG32.DLL
_CG_DESC
__cg_handles
__cg_streams
__cg_streams_cleanup
__cg_memory_cleanup
__cg_object_cleanup
__cg_objecta_cleanup
_CG_VALIDATE
_CG_VALIDATESTRING
__cg_new
__cg_delete
__cg_newa
__cg_deletea
__cg_malloc
__cg_free
__cg_memcpy
__cg_memmove
__cg_memset
__cg_strcmp
__cg_strcpy
__cg_strlen
__cg_strstr
__cg_strtod
__cg_sprintf
__cg_vsnprintf
__cg_fopen
__cg_fclose
__cg_fwrite
__cg_mkdir
__cg_stat
__cg_time
__cg__matherr
__cg__matherrl
__cg_cos
__cg_div
__cg_sin
__cg_sqrt
__cg_atan2
__cg_pow
_cg_lstrcpyA

and the new one:

Imports from CG32.DLL
_CG_DESC
__cg_handles
__cg_streams
__cg_streams_cleanup
__cg_memory_cleanup
__cg_object_cleanup
__cg_objecta_cleanup
_CG_VALIDATE
_CG_VALIDATESTRING
__cg_delete
__cg_newa
__cg_memcpy
__cg__matherr
__cg__matherrl

thank a lot , my english is poor, i hope you can understand... :oops:
rui song
 
Posts: 3
Joined: Mon Aug 24, 2015 10:10 am

Re: the codeguard of my project can't catch memory leak

Postby 2ffat » Tue Aug 25, 2015 4:47 am

I'm not sure this will answer your question but the wisdom around here is when going from the BCB written applications to XE versions it is best to rebuild them. One of the problems is what you describe. Even though you can successfully compile the program, there may be left overs that will eventually create problems down the road. It's best to start from scratch.
James P. Cottingham

Look at me still talking
when there is science to do.
User avatar
2ffat
Forum Mod
Forum Mod
 
Posts: 433
Joined: Wed Jun 23, 2004 7:07 am
Location: South Hill, VA

Re: the codeguard of my project can't catch memory leak

Postby rui song » Tue Aug 25, 2015 7:31 am

2ffat wrote:I'm not sure this will answer your question but the wisdom around here is when going from the BCB written applications to XE versions it is best to rebuild them. One of the problems is what you describe. Even though you can successfully compile the program, there may be left overs that will eventually create problems down the road. It's best to start from scratch.


my boss said start from scratch too...i'll decompose it....let me cry and start to work...thank you sir.
rui song
 
Posts: 3
Joined: Mon Aug 24, 2015 10:10 am

Re: the codeguard of my project can't catch memory leak

Postby 2ffat » Tue Aug 25, 2015 10:09 am

The good news is some, if not most, of your C++ coding should work. You can also change your code to use Unicode now, too.
James P. Cottingham

Look at me still talking
when there is science to do.
User avatar
2ffat
Forum Mod
Forum Mod
 
Posts: 433
Joined: Wed Jun 23, 2004 7:07 am
Location: South Hill, VA

Re: the codeguard of my project can't catch memory leak

Postby rui song » Tue Aug 25, 2015 10:17 am

2ffat wrote:The good news is some, if not most, of your C++ coding should work. You can also change your code to use Unicode now, too.


Oh i think i found the answer why the cg can't catch the memoryleak...

some old bird had made a function to kill the current proccess....

the example just like this:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "tlhelp32.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
char* ch = new char[100];
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
{
/* <---that's why the CG can not catch the memory leak
HANDLE hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,GetCurrentProcessId());
TerminateProcess(hProcess,0);
*/
}

then your codeguarnd can't catch anything.

i can use the CG now!
rui song
 
Posts: 3
Joined: Mon Aug 24, 2015 10:10 am


Return to Technical

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 18 guests

cron