vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.01k stars 120 forks source link

Memory leaks/errors in Forcer #250

Closed tueda closed 6 years ago

tueda commented 6 years ago

With the example in Forcer 1.0, valgrind --leak-check=full vorm example.frm detects some memory leaks

==6515== Memcheck, a memory error detector
==6515== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==6515== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==6515== Command: vorm example.frm
==6515== 
FORM 4.2.0 (Nov 30 2017, v4.2.0-24-g1514492) 64-bits  Run: Thu Dec  7 14:23:11 2017

...

  24.91 sec out of 24.91 sec
==6515== 
==6515== HEAP SUMMARY:
==6515==     in use at exit: 462,708,280 bytes in 7,195 blocks
==6515==   total heap usage: 71,559 allocs, 64,364 frees, 543,302,041 bytes allocated
==6515== 
==6515== 32 bytes in 2 blocks are definitely lost in loss record 34 of 203
==6515==    at 0x4C2AB96: malloc (vg_replace_malloc.c:299)
==6515==    by 0x4FF9B8: Malloc1 (tools.c:2230)
==6515==    by 0x4FF9FC: strDup1 (tools.c:1816)
==6515==    by 0x4AC6A1: DoProcedure (pre.c:3880)
==6515==    by 0x4AF39E: PreProInstruction (pre.c:1156)
==6515==    by 0x4AFF06: PreProcessor (pre.c:931)
==6515==    by 0x4E8ECF: main (startup.c:1605)
==6515== 
==6515== 9,928 bytes in 2 blocks are definitely lost in loss record 157 of 203
==6515==    at 0x4C2AB96: malloc (vg_replace_malloc.c:299)
==6515==    by 0x4FF9B8: Malloc1 (tools.c:2230)
==6515==    by 0x4AC0C9: PreLoad (pre.c:4132)
==6515==    by 0x4AC616: DoProcedure (pre.c:3867)
==6515==    by 0x4AF39E: PreProInstruction (pre.c:1156)
==6515==    by 0x4AFF06: PreProcessor (pre.c:931)
==6515==    by 0x4E8ECF: main (startup.c:1605)
==6515== 
==6515== LEAK SUMMARY:
==6515==    definitely lost: 9,960 bytes in 4 blocks
==6515==    indirectly lost: 0 bytes in 0 blocks
==6515==      possibly lost: 0 bytes in 0 blocks
==6515==    still reachable: 462,698,320 bytes in 7,191 blocks
==6515==         suppressed: 0 bytes in 0 blocks
==6515== Reachable blocks (those to which a pointer was found) are not shown.

In addition to this, for TFORM, valgrind tvorm -w4 example.frm detects memory errors

==6845== Memcheck, a memory error detector
==6845== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==6845== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==6845== Command: tvorm -w4 example.frm
==6845== 
TFORM 4.2.0 (Nov 30 2017, v4.2.0-24-g1514492) 64-bits 4 workers  Run: Thu Dec  7 14:27:00 2017

...

Time =      15.09 sec    Generated terms =          2
               F         Terms in output =          2
       load-topologies-3 Bytes used      =        552

Time =      15.12 sec    Generated terms =          2
               F         Terms in output =          2
           recognition-1 Bytes used      =       1000
==6845== Invalid read of size 4
==6845==    at 0x45338D: DoModDollar (module.c:682)
==6845==    by 0x45370C: DoModLocal (module.c:605)
==6845==    by 0x4526B1: CoModuleOption (module.c:171)
==6845==    by 0x427C05: CompileStatement (compiler.c:634)
==6845==    by 0x4B884B: PreProcessor (pre.c:1045)
==6845==    by 0x4F5233: main (startup.c:1605)
==6845==  Address 0x70702bd0 is 0 bytes after a block of size 96 alloc'd
==6845==    at 0x4C2AB96: malloc (vg_replace_malloc.c:299)
==6845==    by 0x50CB63: Malloc1 (tools.c:2230)
==6845==    by 0x4EF903: EndSort (sort.c:741)
==6845==    by 0x4306C7: CatchDollar (dollar.c:117)
==6845==    by 0x4B8883: PreProcessor (pre.c:1050)
==6845==    by 0x4F5233: main (startup.c:1605)
==6845== 

Time =      15.57 sec    Generated terms =          2
               F         Terms in output =          2
          recognition-2a Bytes used      =       1036
tueda commented 6 years ago

Actually they are 2 different bugs and so it is better to consider them separately.