Opened 7 years ago

Closed 7 years ago

#283 closed defect (wontfix)

Memory leak in Split

Reported by: Maxim Reznik Owned by: somebody
Priority: major Milestone: 0.5.0
Component: Matreshka - League Version: 0.4.0
Keywords: leak split Cc:


with League.Strings;
with League.String_Vectors;

procedure Aaa is
   Target : constant League.Strings.Universal_String :=
     League.Strings.To_Universal_String ("NT.T");
   Items : constant League.String_Vectors.Universal_String_Vector
     := Target.Split ('.');
end Aaa;
with "league";

project aaa is

   for Main use ("aaa.adb");

   package Compiler is
      for Default_Switches ("ada") use
        ("-O0", "-g", "-gnat12");
   end Compiler;

end aaa;

valgrind --leak-check=full --show-reachable=yes ./aaa

==623==     in use at exit: 136 bytes in 3 blocks
==623==   total heap usage: 4 allocs, 1 frees, 184 bytes allocated
==623== 40 bytes in 1 blocks are still reachable in loss record 1 of 3
==623==    at 0x4C2C66D: malloc (in /usr/lib64/valgrind/
==623==    by 0x57B0837: __gnat_malloc (in /home/reznik/local/20121024/lib/gcc/x86_64-pc-linux-gnu/4.7.3/rts-native/adalib/
==623==    by 0x5055C82: matreshka__internals__string_vectors__allocate (matreshka-internals-string_vectors.adb:127)
==623==    by 0x5056433: matreshka__internals__string_vectors__append (matreshka-internals-string_vectors.adb:138)
==623==    by 0x5099DBD: league__strings__split (league-strings.adb:1368)
==623==    by 0x404EE3: _ada_aaa (aaa.adb:8)
==623==    by 0x404BA2: main (b~aaa.adb:409)

Change History (1)

comment:1 by vadim.godunko, 7 years ago

Milestone: 0.5.0
Resolution: wontfix
Status: newclosed

It looks like GNAT bug. GNAT generates to calls to League.Strings.Finalize (one for temporary object and one for Target), but only one for Items (for Items itself, temporary object is not finalized). As result, counter of shared object doesn't reach zero and memory is not deallocated.

It is sufficient to declare Items as object without initialization and assign value inside code block to workaround this bug.

Note: See TracTickets for help on using tickets.