C++ Builder try...catch blocks

delphi package - automated exception handling

C++ Builder try...catch blocks

Postby sutin » Fri Nov 18, 2016 6:13 pm

I have a simple C++ Builder XE10.1 program with a single form and single button. The click event for the button is:

Code: Select all
   Button1->Enabled = false;

  try {
    throw Exception("Well crap, I have an exception");
  catch (const Exception &E) {
    ShowMessage("ERROR:\n\n" + E.Message);

I run the program (with madExcept turned on) and after hitting the button (clicking the exception box) then exiting the application, I get an error reported from MadExcept that 2x28 blocks of memory were allocated and not freed. As far as I'm concerned, this shows an error with C++ Builder's exception handling.

I've looked elsewhere on the web and have found numerous references to this problem but no solutions. Is this truly a bug and if not, how do I get madExcept to ignore it?

Thanks for any help / suggestions. This thing is driving my crazy. I have a huge application that is reporting memory leaks when exceptions are created like the one in the code above.
Posts: 1
Joined: Fri Nov 18, 2016 6:06 pm

Re: C++ Builder try...catch blocks

Postby madshi » Mon Nov 21, 2016 10:50 am

I'm being asked *A LOT* about which reported memory leak might be true and which might be not. To be honest, I'm spending WAY too much time, investigating other companys' source code to check if they have a bug or if madExcept reported a false positive.

Generally, I'd say unless there's a strong indication that madExcept might be reporting a false positive, the reported memory leak is likely a true leak. I'm not sure if there's an easy way to fix it in the BCB code base. Could be quite hard. How often does your application raise exceptions like this? Maybe you can simply ignore these kind of leak reports without being bothered too much by them?

If you want to silently surpress these leak reports, you could try using the following API exported by madExcept.pas:

Code: Select all
// This API allows you to hide leaks based on their callstack.
// e.g. 'MakeObjectInstance|TApplication.Create'
function HideLeak (const callstack: UnicodeString) : boolean; overload;
Site Admin
Posts: 9141
Joined: Sun Mar 21, 2004 5:25 pm

Return to madExcept

Who is online

Users browsing this forum: No registered users and 4 guests