Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks in Hello World program #48

Open
yutaro-sakamoto opened this issue Mar 28, 2022 · 1 comment
Open

Memory leaks in Hello World program #48

yutaro-sakamoto opened this issue Mar 28, 2022 · 1 comment

Comments

@yutaro-sakamoto
Copy link

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)
@GitMensch
Copy link

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), ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants