Skip to content

Memory leaks in Hello World program #48

@yutaro-sakamoto

Description

@yutaro-sakamoto

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions