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: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
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

Expected:
No memory leak is reported.

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

function GetExceptionStackInfo(P: PExceptionRecord): Pointer;
begin
  if (P.ExceptObject <> nil) and (Exception(P.ExceptObject).StackInfo <> nil) then
    Result := Exception(P.ExceptObject).StackInfo
  else
    Result := AllocateStackInfo...;
end;
Attachment
ExceptionStackInfoMemLeak.zip
Comments

None

Server Response from: ETNACODE01