Hi,
I just found 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 IF FAILS
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.
How to reproduce the bug:
1. Compile the attached demo program with heap tracking on
2. Run the demo
3. Click the Show Error (an exception will raised)
4. Quit the program
5. If you run from IDE, check the debug windows => Console in/output
I also attach the patch here.
I've reported the bug here
https://bugs.freepascal.org/view.php?id=38927