Memory Leak
There is a memory leak. I don't know where yet.
In order to find the leak, configure with
cmake -D CMAKE_Fortran_FLAGD="-fsanitize=address" -D CMAKE_BUILD_TYPE=debug ..
Then when you run, you will see the problems.
Compiling as above will tell you that there is a problem, but there isn't much help in finding where the error is. valgrind can help, but you have compile differently:
cmake -D CMAKE_BUILD_TYPE=debug ..
Now you can run with valgrind as shown below. Note, you don't have to have any input deck.
$ valgrind --leak-check=full ../../njoy
==22256== Memcheck, a memory error detector
==22256== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22256== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==22256== Command: ../../njoy
==22256==
==22256== Warning: set address range perms: large range [0x395d8000, 0x8a991000) (defined)
==22256== Warning: set address range perms: large range [0x39f83000, 0x8a991000) (defined)
njoy 2016.44 11Oct18 10/25/18 21:59:33
*****************************************************************************
stop
0.5s
*****************************************************************************
==22256==
==22256== HEAP SUMMARY:
==22256== in use at exit: 280 bytes in 2 blocks
==22256== total heap usage: 55 allocs, 53 frees, 58,511 bytes allocated
==22256==
==22256== 280 (24 direct, 256 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2
==22256== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22256== by 0x4E54854: ??? (in /usr/lib/x86_64-linux-gnu/libgfortran.so.4.0.0)
==22256== by 0x4FD9CD5: ??? (in /usr/lib/x86_64-linux-gnu/libgfortran.so.4.0.0)
==22256== by 0x4FD1512: ??? (in /usr/lib/x86_64-linux-gnu/libgfortran.so.4.0.0)
==22256== by 0x4E538C7: ??? (in /usr/lib/x86_64-linux-gnu/libgfortran.so.4.0.0)
==22256== by 0x40106B9: call_init.part.0 (dl-init.c:72)
==22256== by 0x40107CA: call_init (dl-init.c:30)
==22256== by 0x40107CA: _dl_init (dl-init.c:120)
==22256== by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==22256==
==22256== LEAK SUMMARY:
==22256== definitely lost: 24 bytes in 1 blocks
==22256== indirectly lost: 256 bytes in 1 blocks
==22256== possibly lost: 0 bytes in 0 blocks
==22256== still reachable: 0 bytes in 0 blocks
==22256== suppressed: 0 bytes in 0 blocks
==22256==
==22256== For counts of detected and suppressed errors, rerun with: -v
==22256== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
I got the same result when running with both gfortran-7.3 and gfortran-8.1. It really looks like a bug with the gfortran library.
So, I don't think this is a compiler bug. I've compiled this with:
- gcc/6.4.0
- gcc/7.3.0
- intel/18.0.2
They all have a memory leak. When I run valgrind having compiled with intel, I get the following:
$ valgrind --leak-check=full --show-leak-kinds=all ./njoy
==16074== Memcheck, a memory error detector
==16074== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16074== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==16074== Command: ./njoy
==16074==
==16074== Warning: set address range perms: large range [0x4e36000, 0x5606b000) (defined)
==16074== Warning: set address range perms: large range [0x55dd000, 0x5606b000) (defined)
==16074== Conditional jump or move depends on uninitialised value(s)
==16074== at 0x4C1DAD: __intel_sse2_strcpy (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x46DD53: for__open_proc (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x42E855: for__open_default (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x456B0E: for_write_seq_fmt (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x409BFF: MAIN__ (main.f90:185)
==16074== by 0x4098ED: main (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074==
njoy 2016.44 11Oct18 10/29/18 15:23:30
*****************************************************************************
==16074== Conditional jump or move depends on uninitialised value(s)
==16074== at 0x4C1DAD: __intel_sse2_strcpy (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x46DD53: for__open_proc (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x42E855: for__open_default (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x43EB1B: for_read_seq_lis (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x409D33: MAIN__ (main.f90:191)
==16074== by 0x4098ED: main (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074==
stop
0.9s
*****************************************************************************
==16074==
==16074== HEAP SUMMARY:
==16074== in use at exit: 272 bytes in 2 blocks
==16074== total heap usage: 34 allocs, 32 frees, 36,953 bytes allocated
==16074==
==16074== 32 bytes in 1 blocks are still reachable in loss record 1 of 2
==16074== at 0x4C2B955: calloc (vg_replace_malloc.c:711)
==16074== by 0x56B6E54F: _dlerror_run (dlerror.c:141)
==16074== by 0x56B6E057: dlsym (dlsym.c:70)
==16074== by 0x46B7BE: real_aio_init (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x431ABB: for__once_private (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x41B394: for_rtl_init_ (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x4098E8: main (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074==
==16074== 240 bytes in 1 blocks are still reachable in loss record 2 of 2
==16074== at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==16074== by 0x44730D: for__get_vm (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x431567: for__acquire_threadstor_threads (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x424EE6: for__acquire_lun (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x4484D2: for_write_int_fmt (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074== by 0x52BA245: util_mp_dater_ (util.f90:88)
==16074== by 0x4099C9: MAIN__ (main.f90:158)
==16074== by 0x4098ED: main (in /net/scratch3/jlconlin/NJOY2016/bin/njoy)
==16074==
==16074== LEAK SUMMARY:
==16074== definitely lost: 0 bytes in 0 blocks
==16074== indirectly lost: 0 bytes in 0 blocks
==16074== possibly lost: 0 bytes in 0 blocks
==16074== still reachable: 272 bytes in 2 blocks
==16074== suppressed: 0 bytes in 0 blocks
==16074==
==16074== For counts of detected and suppressed errors, rerun with: -v
==16074== Use --track-origins=yes to see where uninitialised values come from
==16074== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)