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

Possible memory leak in ostei_s_s_s_s.c #12

Closed
colleeneb opened this issue Nov 4, 2018 · 1 comment
Closed

Possible memory leak in ostei_s_s_s_s.c #12

colleeneb opened this issue Nov 4, 2018 · 1 comment

Comments

@colleeneb
Copy link
Contributor

colleeneb commented Nov 4, 2018

Hello,

It looks like there might be a memory leak in ostei_s_s_s_s.c, based on the output of valgrind on one of the test cases:

[bertoni@jlselogin2 test]$ OMP_NUM_THREADS=1 valgrind  --leak-check=full --show-leak-kinds=all ./test_eri ../../test/dat/water.sto-3g.mol
==21988== Memcheck, a memory error detector
==21988== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21988== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==21988== Command: ./test_eri ../../test/dat/water.sto-3g.mol
==21988==

          Quartet      MaxErr     MaxRelErr
(  0  0 |  0  0 )     8.882e-16   7.166e-16
(  0  0 |  0  1 )     1.665e-16   8.373e-16
(  0  0 |  1  0 )     1.665e-16   8.373e-16
(  0  0 |  1  1 )     2.220e-16   5.199e-16
(  0  1 |  0  0 )     1.110e-16   7.467e-16
(  0  1 |  0  1 )     2.776e-17   9.111e-16
(  0  1 |  1  0 )     2.776e-17   8.167e-16
(  0  1 |  1  1 )     1.665e-16   7.012e-16
(  1  0 |  0  0 )     1.665e-16   8.192e-16
(  1  0 |  0  1 )     5.551e-17   9.111e-16
(  1  0 |  1  0 )     5.551e-17   9.111e-16
(  1  0 |  1  1 )     1.110e-16   7.149e-16
(  1  1 |  0  0 )     3.886e-16   7.990e-16
(  1  1 |  0  1 )     1.110e-16   5.623e-16
(  1  1 |  1  0 )     1.388e-16   5.843e-16
(  1  1 |  1  1 )     4.441e-16   5.655e-16

Calculated 2401 contracted integrals

==21988==
==21988== HEAP SUMMARY:
==21988==     in use at exit: 4,616 bytes in 34 blocks
==21988==   total heap usage: 1,362,122 allocs, 1,362,088 frees, 33,479,348 bytes allocated
==21988==
==21988== 8 bytes in 1 blocks are still reachable in loss record 1 of 4
==21988==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==21988==    by 0x5B769C8: gomp_malloc (alloc.c:37)
==21988==    by 0x5B85686: gomp_init_num_threads (proc.c:91)
==21988==    by 0x5B74FFA: initialize_env (env.c:1244)
==21988==    by 0x400FAC2: _dl_init (in /usr/lib64/ld-2.17.so)
==21988==    by 0x4001029: ??? (in /usr/lib64/ld-2.17.so)
==21988==    by 0x1: ???
==21988==    by 0x1FFEFFCC7A: ???
==21988==    by 0x1FFEFFCC85: ???
==21988==
==21988== 192 bytes in 1 blocks are still reachable in loss record 2 of 4
==21988==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==21988==    by 0x5B769C8: gomp_malloc (alloc.c:37)
==21988==    by 0x5B837A5: gomp_get_thread_pool (pool.h:42)
==21988==    by 0x5B837A5: get_last_team (team.c:146)
==21988==    by 0x5B837A5: gomp_new_team (team.c:165)
==21988==    by 0x5B7AC75: GOMP_parallel (parallel.c:167)
==21988==    by 0x4075D7: main (test_eri.cpp:121)
==21988==
**==21988== 1,536 bytes in 16 blocks are definitely lost in loss record 3 of 4
==21988==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==21988==    by 0x4153CE: ostei_s_s_s_s (ostei_s_s_s_s.c:51)
==21988==    by 0x4129D8: simint_compute_ostei (ostei.c:22)
==21988==    by 0x4083C4: main._omp_fn.0 (test_eri.cpp:168)
==21988==    by 0x5B7AC8E: GOMP_parallel (parallel.c:168)
==21988==    by 0x4075D7: main (test_eri.cpp:121)
==21988==
==21988== 2,880 bytes in 16 blocks are definitely lost in loss record 4 of 4
==21988==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==21988==    by 0x415B76: ostei_s_s_s_s (ostei_s_s_s_s.c:83)
==21988==    by 0x4129D8: simint_compute_ostei (ostei.c:22)
==21988==    by 0x4083C4: main._omp_fn.0 (test_eri.cpp:168)
==21988==    by 0x5B7AC8E: GOMP_parallel (parallel.c:168)
==21988==    by 0x4075D7: main (test_eri.cpp:121)**
==21988==
==21988== LEAK SUMMARY:
==21988==    definitely lost: 4,416 bytes in 32 blocks
==21988==    indirectly lost: 0 bytes in 0 blocks
==21988==      possibly lost: 0 bytes in 0 blocks
==21988==    still reachable: 200 bytes in 2 blocks
==21988==         suppressed: 0 bytes in 0 blocks
==21988==
==21988== For counts of detected and suppressed errors, rerun with: -v
==21988== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Based on the message, it looks like there's a pointer that isn't being freed in ostei_s_s_s_s.c:, and I submitted a PR #13 to fix it.

-                if (!offset_info) free(offset_info);
+                if (offset_info != NULL) free(offset_info);

After making the change, valgrind no longer reports that memory is "definitely lost":

[bertoni@jlselogin2 test]$ OMP_NUM_THREADS=1 valgrind  --leak-check=full --show-leak-kinds=all ./test_eri ../../test/dat/water.sto-3g.mol
==24531== Memcheck, a memory error detector
==24531== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24531== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==24531== Command: ./test_eri ../../test/dat/water.sto-3g.mol
==24531==

          Quartet      MaxErr     MaxRelErr
(  0  0 |  0  0 )     8.882e-16   7.166e-16
(  0  0 |  0  1 )     1.665e-16   8.373e-16
(  0  0 |  1  0 )     1.665e-16   8.373e-16
(  0  0 |  1  1 )     2.220e-16   5.199e-16
(  0  1 |  0  0 )     1.110e-16   7.467e-16
(  0  1 |  0  1 )     2.776e-17   9.111e-16
(  0  1 |  1  0 )     2.776e-17   8.167e-16
(  0  1 |  1  1 )     1.665e-16   7.012e-16
(  1  0 |  0  0 )     1.665e-16   8.192e-16
(  1  0 |  0  1 )     5.551e-17   9.111e-16
(  1  0 |  1  0 )     5.551e-17   9.111e-16
(  1  0 |  1  1 )     1.110e-16   7.149e-16
(  1  1 |  0  0 )     3.886e-16   7.990e-16
(  1  1 |  0  1 )     1.110e-16   5.623e-16
(  1  1 |  1  0 )     1.388e-16   5.843e-16
(  1  1 |  1  1 )     4.441e-16   5.655e-16

Calculated 2401 contracted integrals

==24531==
==24531== HEAP SUMMARY:
==24531==     in use at exit: 200 bytes in 2 blocks
==24531==   total heap usage: 1,362,122 allocs, 1,362,120 frees, 33,479,348 bytes allocated
==24531==
==24531== 8 bytes in 1 blocks are still reachable in loss record 1 of 2
==24531==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==24531==    by 0x5B769C8: gomp_malloc (alloc.c:37)
==24531==    by 0x5B85686: gomp_init_num_threads (proc.c:91)
==24531==    by 0x5B74FFA: initialize_env (env.c:1244)
==24531==    by 0x400FAC2: _dl_init (in /usr/lib64/ld-2.17.so)
==24531==    by 0x4001029: ??? (in /usr/lib64/ld-2.17.so)
==24531==    by 0x1: ???
==24531==    by 0x1FFEFFCC7A: ???
==24531==    by 0x1FFEFFCC85: ???
==24531==
==24531== 192 bytes in 1 blocks are still reachable in loss record 2 of 2
==24531==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==24531==    by 0x5B769C8: gomp_malloc (alloc.c:37)
==24531==    by 0x5B837A5: gomp_get_thread_pool (pool.h:42)
==24531==    by 0x5B837A5: get_last_team (team.c:146)
==24531==    by 0x5B837A5: gomp_new_team (team.c:165)
==24531==    by 0x5B7AC75: GOMP_parallel (parallel.c:167)
==24531==    by 0x4075D7: main (test_eri.cpp:121)
==24531==
==24531== LEAK SUMMARY:
==24531==    definitely lost: 0 bytes in 0 blocks
==24531==    indirectly lost: 0 bytes in 0 blocks
==24531==      possibly lost: 0 bytes in 0 blocks
==24531==    still reachable: 200 bytes in 2 blocks
==24531==         suppressed: 0 bytes in 0 blocks
==24531==
==24531== For counts of detected and suppressed errors, rerun with: -v
==24531== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

I think this is the correct fix, but let me know if I'm missing something. Thanks!

bennybp added a commit that referenced this issue Dec 11, 2018
Change in ostei to free pointer, Issue #12
@bennybp
Copy link
Contributor

bennybp commented Dec 11, 2018

Fixed in PR #13

@bennybp bennybp closed this as completed Dec 11, 2018
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