Re: [fpc-pascal] Memory Leak's in XMLRead unit
On Wed, Nov 8, 2017 at 10:52 AM, African Wild Dogwrote: > 2017-11-07 23:57 GMT-02:00 Michael Van Canneyt : >> >> ... >> > My environment: Linux Debian Stretch 64 bits - Lazarus 1.6.4 - fpc 3.0.2. > > I'm quite impressed with the processing power of fastcgi fcl-web > applications: they consume little memory (less than 2 MB per instance) and > are very fast to process the requests. It is fast even on Windows+IIS. ;) Best regards, Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Memory Leak's in XMLRead unit
On Wed, 8 Nov 2017, African Wild Dog wrote: 2017-11-07 23:57 GMT-02:00 Michael Van Canneyt: 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. In fact, protecting with Try..Except does not generate the leak. That is because you catch the exception object. If you enable line info, you see that the unreleased memory is the exception object and its error message. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Memory Leak's in XMLRead unit
2017-11-07 23:57 GMT-02:00 Michael Van Canneyt: > > 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. > In fact, protecting with Try..Except does not generate the leak. I will try to reproduce this error again. I noticed this behavior in my FCGI APP: a client was sending a mal-formed XML content and my app was generating the leaks. My environment: Linux Debian Stretch 64 bits - Lazarus 1.6.4 - fpc 3.0.2. I'm quite impressed with the processing power of fastcgi fcl-web applications: they consume little memory (less than 2 MB per instance) and are very fast to process the requests. Regards ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Memory Leak's in XMLRead unit
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 = '<<>>'; 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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Memory Leak's in XMLRead unit
Hi, if I run the code it writes "Unhandled exception". I tried to add another try..except block and it's OK. program xml_leak_test; {$mode objfpc} uses heaptrc, Classes, DOM, XMLRead; var XMLDocument: TXMLDocument; InvalidStream: TStringStream; const INVALID_XML_CONTENT = '<<>>'; begin SetHeapTraceOutput('heap.trc'); XMLDocument := nil; InvalidStream := TStringStream.Create(INVALID_XML_CONTENT); try try ReadXMLFile(XMLDocument, InvalidStream); except end; finally InvalidStream.Free; XMLDocument.Free; end; end. Note: when I tried your original code in Lazaur method, it didn't leak at all. V. __ > Od: African Wild Dog <paintedlyc...@gmail.com> > Komu: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org> > Datum: 07.11.2017 23:19 > Předmět: [fpc-pascal] Memory Leak's in XMLRead unit > Hello,Using ReadXMLFile function from XMLRead unit generates memory leaks when trying to read a invalid XML content. -- ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Memory Leak's in XMLRead unit
Hello, Using ReadXMLFile function from XMLRead unit generates memory leaks when trying to read a invalid XML content. CODE program xml_leak_test; uses heaptrc, Classes, DOM, XMLRead; var XMLDocument: TXMLDocument; InvalidStream: TStringStream; const INVALID_XML_CONTENT = '<<>>'; begin SetHeapTraceOutput('heap.trc'); XMLDocument := nil; InvalidStream := TStringStream.Create(INVALID_XML_CONTENT); try ReadXMLFile(XMLDocument, InvalidStream); finally InvalidStream.Free; XMLDocument.Free; end; end. === HEAP trace content: HEAP === Heap dump by heaptrc unit 105 memory blocks allocated : 18943/19216 101 memory blocks freed : 18639/18912 4 unfreed memory blocks : 304 True heap size : 491520 (192 used in System startup) True free heap : 490400 Should be : 490512 Call trace for block $011EA650 size 40 $0001B7AB $000100010A62 $000100010B6C $7720812D $771F855F $7722BCB8 $07FEFD0BA06D $BAADF00DBAADF00D Call trace for block $01200B80 size 128 $0001000141E6 $0001B78B $0001000107D7 $000100010896 $000100037D56 $000100037C6E $000100037A82 $BAADF00DBAADF00D Call trace for block $01208B70 size 88 $000100014347 $0001B78B $00015E15 $0001513A $00010002B9E8 $00010002C000 $00010002E4AF $BAADF00DBAADF00D Call trace for block $011EA350 size 48 $0001B6F2 $000190A7 $0001000360A1 $000100037C42 $000100037A82 $00010003786B $0001000389F8 $BAADF00DBAADF00D == ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal