Memory leak on lr_class.LoadFromXMLStream
Original Reporter info from Mantis: bpranoto
-
Reporter name: Bambang Pranoto
Original Reporter info from Mantis: bpranoto
- Reporter name: Bambang Pranoto
Description:
There's a memory leak in lr_class.pas method LoadFromXMLStream
procedure TfrReport.LoadFromXMLStream(const Stream: TStream);
var
XML: TLrXMLConfig;
begin
XML := TLrXMLConfig.Create(nil);
XML.LoadFromStream(Stream); // <==== MEMORY LEAK
try
LoadFromXML(XML, 'LazReport/');
FileName := '-stream-';
finally
XML.Free;
end;
end;
Because the call of LoadFromStream() is outside the try..finally block, if XML.LoadFromStream(Stream) fails, the XML won't be freed, hence a memory leak occurs.
Steps to reproduce:
- Compile the attached demo program with heap tracking on
- Run the demo
- Click the Show Error (an exception will raised)
- Quit the program
- If you run from IDE, check the debug windows => Console in/output
Additional information:
Attached is my patch to fix the memory leak
Mantis conversion info:
- Mantis ID: 38927
- OS: ubuntu
- OS Build: ubuntu 18.04 64b
- Platform: Linux
- Version: 2.0.12
- Fixed in version: 2.1 (SVN)
- Fixed in revision: 65140 (#752d4a39)
- Target version: 2.2