Hello.
I'm looking for a quite "interesting" bug I'm using fortran 90, compiler gfortran and the main idea is for every time step I build a bin structure for search contact between particles, for this at the begining
TYPE :: circle_index
INTEGER(kind = 4) :: ind_p
TYPE(circle_index), POINTER :: p
END TYPE
TYPE(circle_index), DIMENSION(:), POINTER :: Bins(:)
TYPE(circle_index), DIMENSION(:), POINTER :: Bins_Tail(:)
TYPE(circle_index),POINTER :: headB
And the next part it's called almost every time step.
I compute rows and colums variables for allocate memory
ALLOCATE(Bins(rows*columns),Bins_Tail(rows*columns))
Then I do the search for finally
DO pos = 1, rows*columns
headB => Bins(pos)%p
DO
IF(.NOT. ASSOCIATED(headB)) EXIT
ptr_index => headB%p
DEALLOCATE(headB)
headB => ptr_index
END DO
END DO
DEALLOCATE(Bins, Bins_Tail)
The search is ok, but I get some of these errors
*** glibc detected *** double free or corruption (out)
*** glibc detected *** free(): invalid next size (normal)
And it's wierd for me because if I'm deallocating in the wrong way I expect the error at the beginig but it does not. The error just appear more after, am I doing it wrong?
I already use -fbounds-check but does not work and is really dificult debug step by step because the simulation is very long, so any ideas?
Does anybody have an idea what is happening here? Have you seen something similar yet? What could i still try?
Greetings & thank you,
Marce.