[fpc-pascal] Memory Leak's in XMLRead unit

Michael Van Canneyt michael at freepascal.org
Wed Nov 8 02:57:02 CET 2017



On Tue, 7 Nov 2017, African Wild Dog wrote:

> Hello,
>
> Using ReadXMLFile function from XMLRead unit generates memory leaks when
> trying to read a invalid XML content.

The "memory leak" is the exception object: you are not catching the exception.

Change your program to the below, and you'll see that it is not leaking
memory in the XML routines itself.

Michael.

---

program xml_leak_test;

uses
   Classes,
   DOM,
   XMLRead;

Procedure doit;

var
   XMLDocument: TXMLDocument;
   InvalidStream: TStringStream;

const
   INVALID_XML_CONTENT = '<<<INVALID XML>>>';

begin

   XMLDocument := nil;
   InvalidStream := TStringStream.Create(INVALID_XML_CONTENT);
   try
      ReadXMLFile(XMLDocument, InvalidStream);
   finally
     InvalidStream.Free;
     XMLDocument.Free;
   end;
end;

begin
   SetHeapTraceOutput('heap.trc');
   try
     doit;
   except
   end; 
end.



More information about the fpc-pascal mailing list