Recent

Author Topic: lazreport: Memory leak on LoadFromXMLStream  (Read 2476 times)

bpranoto

  • Full Member
  • ***
  • Posts: 103
lazreport: Memory leak on LoadFromXMLStream
« on: May 24, 2021, 05:17:21 am »
Hi,

I just found a memory leak in lr_class.pas method LoadFromXMLStream.

Code: Pascal  [Select][+][-]
  1. procedure TfrReport.LoadFromXMLStream(const Stream: TStream);
  2. var
  3.   XML: TLrXMLConfig;
  4. begin
  5.   XML := TLrXMLConfig.Create(nil);
  6.   XML.LoadFromStream(Stream);  // <= MEMORY LEAK IF FAILS
  7.   try
  8.     LoadFromXML(XML, 'LazReport/');
  9.     FileName := '-stream-';
  10.   finally
  11.     XML.Free;
  12.   end;
  13. end;
  14.  

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

jamie

  • Hero Member
  • *****
  • Posts: 4841
Re: lazreport: Memory leak on LoadFromXMLStream
« Reply #1 on: May 24, 2021, 10:36:50 pm »
why don't you report it to the bug page ?
The only true wisdom is knowing you know nothing

bpranoto

  • Full Member
  • ***
  • Posts: 103
Re: lazreport: Memory leak on LoadFromXMLStream
« Reply #2 on: May 25, 2021, 07:52:44 am »
I did. See the last sentence of my post.

Quote
I've reported the bug here https://bugs.freepascal.org/view.php?id=38927

 

TinyPortal © 2005-2018