opensource-cobol icon indicating copy to clipboard operation
opensource-cobol copied to clipboard

Memory leaks in `Hello World` program

Open yutaro-sakamoto opened this issue 3 years ago • 1 comments

I used valgrind memory check against 'Hello World' program and found memory leaks.

       IDENTIFICATION              DIVISION.
       PROGRAM-ID.                 hello.
       DATA                        DIVISION.
       WORKING-STORAGE             SECTION.
       PROCEDURE                   DIVISION.
           DISPLAY "Hello".
           STOP RUN.
$ cobc -g -x hello.cbl
$ valgrind --leak-check=full --show-leak-kinds=all --tool=memcheck ./hello
==3009== Memcheck, a memory error detector
==3009== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3009== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==3009== Command: ./hello
==3009==
Hello
==3009==
==3009== HEAP SUMMARY:
==3009==     in use at exit: 35,883 bytes in 171 blocks
==3009==   total heap usage: 211 allocs, 40 frees, 45,470 bytes allocated
==3009==
==3009== 2 bytes in 1 blocks are definitely lost in loss record 1 of 38
==3009==    at 0x4C360A5: malloc (vg_replace_malloc.c:380)
==3009==    by 0x5D1480D: strdup (in /usr/lib64/libc-2.28.so)
==3009==    by 0x4E5253C: cob_init (in /usr/lib/libcob.so.1.0.0)
==3009==    by 0x400B55: main (hello.c:31)
==3009==
==3009== LEAK SUMMARY:
==3009==    definitely lost: 2 bytes in 1 blocks
==3009==    indirectly lost: 0 bytes in 0 blocks
==3009==      possibly lost: 0 bytes in 0 blocks
==3009==    still reachable: 35,881 bytes in 170 blocks
==3009==         suppressed: 0 bytes in 0 blocks
==3009== Reachable blocks (those to which a pointer was found) are not shown.
==3009== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3009==
==3009== For lists of detected and suppressed errors, rerun with: -s
==3009== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

yutaro-sakamoto avatar Mar 28 '22 07:03 yutaro-sakamoto

Once this is fixed you'd likely want to run the NIST testsuite through valgrind's memcheck (adjusting the constants in tests/cobol85/report.pl).

Note: I'd suggest to copy over the complete folder tests/cobol85 from current GnuCOBOL but the the summary*.txt (to not stumble over not working tests). This adds all the nice things that you find in the ChangeLog of this folder, between others: support for very old and recent perl, duration logs (that helps a lot when working on optimization), ...

GitMensch avatar Mar 28 '22 07:03 GitMensch