[fpc-pascal] possible json parser memory leak

ik idokan at gmail.com
Sun Dec 18 18:21:03 CET 2011


Hello,

I'm using FPC 2.6 (rc) x86_64 on Linux with JSONParser.

I've written the following code:

-----------------------
uses fpjson, jsonparser, SysUtils, classes;

var
  parser    : TJSONParser;
  json_file : TFileStream;

begin
  json_file := TFileStream.Create('/tmp/test.json', fmOpenRead);
  json_file.position := 0;
  parser := TJSONParser.create(json_file);
  writeln('JSON: ', parser.Parse.AsJSON);
  FreeAndNil(parser);
  FreeAndNil(json_file);
end.
---------------------

It works well, but compiling with -gh gives the following return:
$ ./test_json
JSON: { "Hello" : "World", "TheAnswerForWorldUniverseAndEverything" : 42,
"Array" : ["a", 1,  3.14000000000000E+000] }
Heap dump by heaptrc unit
70 memory blocks allocated : 7060/7208
53 memory blocks freed     : 6274/6408
17 unfreed memory blocks : 786
True heap size : 458752
True free heap : 455296
Should be : 455776
Call trace for block $00007FA261D57660 size 16
  $000000000042BB8C
  $000000000042B974
  $000000000042BEA7
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D575C0 size 16
  $000000000042BAED
  $000000000042B974
  $000000000042BEA7
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67E40 size 32
  $000000000041637A
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D57520 size 16
  $000000000042B918
  $000000000042BEA7
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67D80 size 18
  $0000000000499691
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67CC0 size 24
  $000000000047C0D8
  $000000000047BE34
  $0000000000428B13
  $000000000042BE45
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
Call trace for block $00007FA261D67C00 size 24
  $0000000000428B13
  $000000000042BE45
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D57480 size 16
  $000000000042BE45
  $000000000042B94F
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D57340 size 16
  $000000000042BAED
  $000000000042B974
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
  $0000000000400180
Call trace for block $00007FA261D5F520 size 70
  $000000000041637A
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67B40 size 20
  $000000000041637A
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D470C0 size 384
  $000000000041637A
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D573E0 size 16
  $000000000042B918
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67A80 size 22
  $0000000000499691
  $000000000042BCF8
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D5F440 size 56
  $000000000047EA32
  $000000000042A53B
  $000000000042BC43
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D67900 size 24
  $000000000042A53B
  $000000000042BC43
  $000000000042B92A
  $000000000042B663
  $0000000000400180
Call trace for block $00007FA261D572A0 size 16
  $000000000042BC43
  $000000000042B92A
  $000000000042B663
  $0000000000400180


Is that a memory leak in the library, or am I missing something here ?
Thanks,
Ido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111218/4be282ff/attachment.html>


More information about the fpc-pascal mailing list