A user reported an error to me where the line
read(unit_chk) ((kpt_latt(i,nkp),i=1,3),nkp=1,num_kpts)
failed with the error (similar to Why do I get a C malloc assertion failure?)
malloc.c:2365: sysmalloc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask)
== 0)' failed.
Abort
As far as I know, the error occurs only for a specific set of inputs. Also, when the read()
is changed to the equivalent
((kpt_latt(i,nkp),i=1,3),nkp=1,(num_kpts-1)), &
kpt_latt(1,num_kpts),kpt_latt(2,num_kpts),kpt_latt(3,num_kpts)
the error disappears. Even compiling with a different compiler version (IntelStudio 2013 SP1 composer_xe_2013_sp1.2.144
instead of IntelStudio 2015 composer_xe_2015.6.233
) made the error disappear. (This is all from the user's reports -- I have not yet reproduced the error.)
When the program is run through valgrind
, it reports
valgrind: m_mallocfree.c:268 (mk_plain_bszB): Assertion 'bszB != 0' failed.
valgrind: This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata. If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away. Please try that before reporting this as a bug.
Before that, there area a couple of messages that Conditional jump or move depends on uninitialised value(s)
, Use of uninitialised value of size 8
and Invalid read of size 8
; and one Invalid write of size 1
on the statement cited above.
The array that is being read into is allocated to the proper size just one line before:
allocate(kpt_latt(3,num_kpts))
read(unit_chk) ((kpt_latt(i,nkp),i=1,3),nkp=1,num_kpts)
EDIT: The user has reported back with a possible solution. The array kpt_latt
that is being read was declared with a wrong data type, namely as integer
while the data in the file was written as real
. This is an error of course; but is it realistic that this caused the failed malloc()
assertion?
Fine print: We are talking about a default-kind integer
(4 bytes) and a double precision real (8 bytes) here. The resulting bogus values in kpt_latt
were not noticed because the program does not actually use them. I still have not reproduced the error myself, so I have to rely on what the user tells me.