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

2017-11-08 Thread Marcos Douglas B. Santos
On Wed, Nov 8, 2017 at 10:52 AM, African Wild Dog
 wrote:
> 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

2017-11-08 Thread Michael Van Canneyt



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-08 Thread African Wild Dog
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

2017-11-07 Thread Michael Van Canneyt



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

2017-11-07 Thread Vojtěch Čihák

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 
> Komu: FPC-Pascal users discussions 
> 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 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal