ossama-othman / MaRC

MaRC - Map Reprojections and Conversions
GNU Lesser General Public License v2.1
1 stars 0 forks source link

Input file scanner shows "reachable blocks" after subsequent yyrestart() #84

Closed ossama-othman closed 6 years ago

ossama-othman commented 6 years ago

Valgrind reports reachable blocks when calling the yyrestart() Flex scanner function:

foo@bar:~MaRC/tests$ ../libtool --mode=execute valgrind --leak-check=full --show-leak-kinds=all ../src/marc test_mercator.marc
==18699== Memcheck, a memory error detector
==18699== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==18699== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==18699== Command: /home/foo/MaRC/src/.libs/marc test_mercator.marc
==18699== 

Creating map: test_map_mercator.fits
Plane 1 / 9 : .........20.........40.........60.........80.........100%
Plane 2 / 9 : .........20.........40.........60.........80.........100%
Plane 3 / 9 : .........20.........40.........60.........80.........100%
Plane 4 / 9 : .........20.........40.........60.........80.........100%
Plane 5 / 9 : .........20.........40.........60.........80.........100%
Plane 6 / 9 : .........20.........40.........60.........80.........100%
Plane 7 / 9 : .........20.........40.........60.........80.........100%
Plane 8 / 9 : .........20.........40.........60.........80.........100%
Plane 9 / 9 : .........20.........40.........60.........80.........100%
Completed mapping data in 0.771331 seconds.
Completed mapping grid in 0.00249204 seconds.
==18699== 
==18699== HEAP SUMMARY:
==18699==     in use at exit: 16,458 bytes in 3 blocks
==18699==   total heap usage: 5,683 allocs, 5,680 frees, 4,782,387 bytes allocated
==18699== 
==18699== 8 bytes in 1 blocks are still reachable in loss record 1 of 3
==18699==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18699==    by 0x13103E: yyalloc (lexer.cc:3697)
==18699==    by 0x13103E: yyensure_buffer_stack() (lexer.cc:3393)
==18699==    by 0x13136C: yyrestart(_IO_FILE*) (lexer.cc:3170)
==18699==    by 0x112BC7: main (marc.cpp:84)
==18699== 
==18699== 64 bytes in 1 blocks are still reachable in loss record 2 of 3
==18699==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18699==    by 0x1312A2: yyalloc (lexer.cc:3697)
==18699==    by 0x1312A2: yy_create_buffer(_IO_FILE*, int) (lexer.cc:3232)
==18699==    by 0x13138F: yyrestart(_IO_FILE*) (lexer.cc:3172)
==18699==    by 0x112BC7: main (marc.cpp:84)
==18699== 
==18699== 16,386 bytes in 1 blocks are still reachable in loss record 3 of 3
==18699==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18699==    by 0x1312B8: yyalloc (lexer.cc:3697)
==18699==    by 0x1312B8: yy_create_buffer(_IO_FILE*, int) (lexer.cc:3241)
==18699==    by 0x13138F: yyrestart(_IO_FILE*) (lexer.cc:3172)
==18699==    by 0x112BC7: main (marc.cpp:84)
==18699== 
==18699== LEAK SUMMARY:
==18699==    definitely lost: 0 bytes in 0 blocks
==18699==    indirectly lost: 0 bytes in 0 blocks
==18699==      possibly lost: 0 bytes in 0 blocks
==18699==    still reachable: 16,458 bytes in 3 blocks
==18699==         suppressed: 0 bytes in 0 blocks
==18699== 
==18699== For counts of detected and suppressed errors, rerun with: -v
==18699== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Look into clearing these reachable blocks, possibly by leveraging yy_delete_buffer() or YY_FLUSH_BUFFER. Switching to a reentrant scanner may also help.