Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/RTL Exceptions    [ Add a report in this area ]  
Report #:  101329   Status: Open
Exception.StackInfo leaks if AcquireExceptionObject is used
Project:  Delphi Build #:  16.0.4316.44803
Version:    16.2 Submitted By:   Andreas Hausladen
Report Type:  Minor failure / Design problem Date Reported:  11/25/2011 1:37:19 PM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   288975
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 1
Exceptions leak memory for the StackInfo if an stack info provider is installed (Exception.GetExceptionStackInfoProc) and the AcquireExceptionObject function is used. This is because the GetExceptionStackInfoProc is called when the exception is raised. But if the exception is raised again after a call to AcquireExceptionObject, the StackInfo field is overwritten and the value from the previous call to GetExceptionStackInfoProc is lost.

A possible fix is to skip the call to GetExceptionStackInfoProc if the StackInfo field already has a value.

This bug exists since the StackInfo was introduced.
Steps to Reproduce:
1. Open the attached project in XE2
2. Start it

No memory leak is reported.

It outputs "Memory leaked" and the memory manager shows the memory leak report for the string that was allocated in GetExceptionStackInfo
Return the already allocated StackInfo if the ExceptionRecord.ExceptObject.StackInfo is not nil.

function GetExceptionStackInfo(P: PExceptionRecord): Pointer;
  if (P.ExceptObject <> nil) and (Exception(P.ExceptObject).StackInfo <> nil) then
    Result := Exception(P.ExceptObject).StackInfo
    Result := AllocateStackInfo...;


Server Response from: ETNACODE01