i am currently experiencing a problem were i get
*** glibc detected *** ./efit: free(): invalid next size (fast): 0x00000000006127f0 ***
with the usual memory map and backtrace information that comes with a glibc
error. i am, however, unable to find the cause of this problem. it seems like (basically) my entire program is finished by the time this happens. one thing i read online is that this could be due to lack of deallocation.
now, i have been running the program without deallocating a few of my arrays (i was under the impression that deallocation can cause memory leaks but that this will only affect the performance and efficiency of the program while it runs). now, when i start the program fresh, i am running into this error.
is it possible that my previous executions of the program without deallocating my arrays is 'coming back to haunt me' in the sense that there is unfree memory from previous executions which i am trying to write to?
if not i am completely confused by this error. any clues on where i should begin to look and/or how i should debug to find it?
for what it is worth, i am using gfortran to compile
EDIT:
while the compilation options did not directly identify this problem at first, it helped me to whittle it away. i was using an integer variable iat
for iat=1,natoms
in a do
loop, and then a few lines later, thought iat
was describing a different integer within the bounds of 1,natoms
. i was referencing an array outside the bounds of the array. when i corrected a few of the warnings listed by your compilation options, this error turned into a much clearer description of the error: Fortran runtime error: Index '7' of dimension 1 of array 'isnormed' above upper bound of 6
.
What was it that kept this error from being produced the first time? the only reach changes i made which the compilation warnings told me about were changing read(fout, '(a)'), line100' to
read(fout, '(a)') line100' (removing the comma) and changing old style character descriptions character*100 line100
to newer character(100) line100
descriptions.
This message is not about failure to deallocate. It's saying the heap is corrupt. There are many ways this can occur, but forgetting to free an array is not one of them. Must likely if this is Fortran code is an array incorrectly declared.
The message is being generated when
glibc
does a consistency check. So when the message occurs (beginning or end of the run) is not relevant except that you know the corruption occurred at some time (but could be any time) before the message appeared.A corrupt heap means that the answers your program is generating may be anything from perfectly correct to completelyl useless. You'll have to get rid of this message.
This is backward. Memory leaks occur when deallocation is not done.
The best way forward is to use a tool like
valgrind
designed to detect and report heap problems in detail.An error from a previous run of your program cannot effect the next run. The OS loads a new version of the executable and provides it with memory. Only if you have the program write out info to a file and read it in on the next run can their be transfer of information.
Memory is automatically deallocated by the OS when the program finishes. Additionally, for Fortran >=95, allocatable arrays that are local to a procedure are automatically deallocated by Fortran when the procedure returns.
Most likely you have a memory usage problem that is corrupting the internal structures that describe memory that is used by your program. With Fortran this is possible by having argument mismatched between caller and callee, by indexing past the end of an array, or with pointers. Are you using pointers? If not, the first two are typically easy to guard against in this era. Place your procedures into modules and "use" those modules. This will allow the compiler to check argument consistency. Compile with the option for run-time checking of subscripts. This will find out if you are indexing past the end of an array and storing in other memory.
With gfortran, try the following compiler options: -O2 -fimplicit-none -Wall -Wline-truncation -Wcharacter-truncation -Wsurprising -Waliasing -Wimplicit-interface -Wunused-parameter -fwhole-file -fcheck=all -std=f2008 -pedantic -fbacktrace. If some of these identify too many warnings, the important one for this issue is fcheck=all, or even narrower, fcheck=bounds.