Memory leaks when using openmp

Andres Tiraboschi andres.tiraboschi@tallertechnologies.com
Fri May 15 12:41:00 GMT 2015


Hi, when I use openmp in gcc 4.8.3 valgrind is reporting some leaks.
Here is a example:

test.cpp:

----------------------------------------------------------
#include <omp.h>

int main(void)
{
    int a = 0;
    #pragma omp parallel
        a = omp_get_thread_num();
    return 0;
}
-------------------------------------------------------------

and here is the valgrind report:

--------------------------------------------------------------------------------------------------
valgrind --leak-check=full --show-leak-kinds=all ./a.out
==2635== Memcheck, a memory error detector
==2635== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==2635== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==2635== Command: ./a.out
==2635==
==2635==
==2635== HEAP SUMMARY:
==2635==     in use at exit: 2,936 bytes in 6 blocks
==2635==   total heap usage: 6 allocs, 0 frees, 2,936 bytes allocated
==2635==
==2635== 40 bytes in 1 blocks are still reachable in loss record 1 of 4
==2635==    at 0x4A0645D: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2635==    by 0x4A0832B: realloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2635==    by 0x4F2F858: gomp_realloc (alloc.c:54)
==2635==    by 0x4F33A3A: gomp_team_start (team.c:376)
==2635==    by 0x40075A: main (test.cpp:6)
==2635==
==2635== 192 bytes in 1 blocks are still reachable in loss record 2 of 4
==2635==    at 0x4A0645D: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2635==    by 0x4F2F808: gomp_malloc (alloc.c:36)
==2635==    by 0x4F33BCE: gomp_team_start (team.c:190)
==2635==    by 0x40075A: main (test.cpp:6)
==2635==
==2635== 912 bytes in 3 blocks are possibly lost in loss record 3 of 4
==2635==    at 0x4A081D4: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2635==    by 0x3ECCA11C24: _dl_allocate_tls (in /usr/lib64/ld-2.18.so)
==2635==    by 0x3ECDA0880A: pthread_create@@GLIBC_2.2.5 (in
/usr/lib64/libpthread-2.18.so)
==2635==    by 0x4F33955: gomp_team_start (team.c:439)
==2635==    by 0x40075A: main (test.cpp:6)
==2635==
==2635== 1,792 bytes in 1 blocks are still reachable in loss record 4 of 4
==2635==    at 0x4A0645D: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2635==    by 0x4F2F808: gomp_malloc (alloc.c:36)
==2635==    by 0x4F33535: gomp_new_team (team.c:144)
==2635==    by 0x4F324DB: GOMP_parallel_start (parallel.c:108)
==2635==    by 0x40075A: main (test.cpp:6)
==2635==
==2635== LEAK SUMMARY:
==2635==    definitely lost: 0 bytes in 0 blocks
==2635==    indirectly lost: 0 bytes in 0 blocks
==2635==      possibly lost: 912 bytes in 3 blocks
==2635==    still reachable: 2,024 bytes in 3 blocks
==2635==         suppressed: 0 bytes in 0 blocks
==2635==
==2635== For counts of detected and suppressed errors, rerun with: -v
==2635== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)

---------------------------------------------------------------------------------------------------------

I also checked that the omp destructors are not being called, I'd like
to know if someone else is having the same issue.

Regards,
Andres



More information about the Gcc-help mailing list