Troubleshoot C + + Builder Codegurad issues.

Source: Internet
Author: User

About C + + BUILDER6 I don't know what's particularly good for a memory troubleshooter at the moment. Especially in order to deal with memory leak, (eurekalog, this tool is mainly for DELPHI,BCB configuration is cumbersome). In addition to BCB6 's own codeguard. Codeguard is still very strong in the 90% situation.

But the actual project Codegurad will strike for a variety of reasons. The following are 2 cases of record codeguard being repaired

    • After the CG is loaded, the program runs up and reports a memory error.

This problem bothered me for a long time and finally had to close the Codeguard until one day, I decided to solve the problem. I think this is not BCB problem, why, because any new project CG work is normal. That's how I did it. Using Tdump to see the library referenced by EXE (intuitively told me), the results found that the project quoted VCL50.BPL. And my project was built by BCB6.

So I found this module using VCL50.BPL, which is a library of LIB, a reference to a third party. I cut off the library. Run CG. REBUILD, Fix it. The program can run normally. It also identifies a memory leak.

    • CG is loaded successfully, but CG does not recognize a memory leak.

The problem is rather weird. The program can run normally and can also load CG. However, you deliberately triggered a memory leak in the program, CG actually did not have any reaction. I insist that it is not a matter of BCB. The reason is that the new project can normally identify the memory leak problem. That's what I'm doing.

At the entrance of the WinMain function, a memory leak is thrown and then the direct return 0

1 int WINAPI WinMain (...) 2 {3charnewchar[ten]; 4 return 0 ; 5 }

CG identifies a memory leak. So I judged that after a certain piece of code was executed , the CG could not work properly.

So, I kept moving the return 0 position. Until you find the piece of code that CG does not report a memory leak.

int WINAPI winMain (...) {charnewchar[ten]; code 1 Code 2 Code 3  //<-After executing code 3, CG will not report memory errors.  return0}

Continue troubleshooting internal issues in code 3.

Finally, locate the code that has a very exited process in the code. Led to the CG not recognized. A simple example is used to simulate this.

Create a new project, then open CG, drag a button Button1, the code is as follows.

//---------------------------------------------------------------------------#include<vcl.h>#pragmaHdrstop#include"Unit1.h"#include"tlhelp32.h"//---------------------------------------------------------------------------#pragmaPackage (Smart_init)#pragmaResource "*.DFM"TForm1*Form1;//---------------------------------------------------------------------------__fastcall Tform1::tform1 (tcomponent*owner): Tform (owner) {Char* ch =New Char[ -];}//---------------------------------------------------------------------------void__fastcall Tform1::button1click (TObject *Sender) {HANDLE hprocess=OpenProcess (Process_terminate,false,getcurrentprocessid ()); TerminateProcess (hprocess,0); }

You will find that Button1, CG will not report any memory leaks. Well understood, this action is equivalent to killing the process in the process manager. CG naturally does not report any mistakes.

In other words, if your CG can compile correctly, but not error. Then check that your program ends with a normal return from WinMain.

Troubleshoot C + + Builder Codegurad issues.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.