Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What can go wrong with deallocate?

Status
Not open for further replies.

svar

Programmer
Aug 12, 2001
349
GR
I have rewritten legacy code to use allocatable arrays
I am defining these in the Subroutine that calls the ode solver
DOUBLE PRECISION, dimension:)), ALLOCATABLE :: ATOL ,RTOL
DOUBLE PRECISION, dimension:)), ALLOCATABLE :: WORK
integer, DIMENSION:)), allocatable :: IWORK
allocate (RTOL(NEQ ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate rtol in solve0U0'
stop 1
end if
allocate (ATOL(NEQ ), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate atol in solve0U0'
stop 1
end if




allocate (WORK(NRWRKRAD), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate WORK in solveOU0'
stop 1
end if
allocate (IWORK(NIWRKRAD), stat=iaLLOCATEstatus)
if (IALLOCATEstatUS /= 0) then
write(6,*)'ERROR trying to allocate IWORK in solve0U0'
stop 1
end if
.......
22 CALL RADAU5( NEQ,FCN,T,Y,TOUT,H,
& RTOL,ATOL,ITOL,
& DJAC,
& IJAC,MLJAC,MUJAC, DUMMAS,
z IMAS,MLMAS,MUMAS,
c ok thus far
& SOLOUT,0,
z LDATIMES,NSUP,URESUR,URESUI,
& WORK,NRWRKRAD,
z IWORK,NIWRKRAD,RPAR,IPAR, IDID)
c radau5 has rtol, atol and work, iwork, dimensioned to their allocated dimensions
....................
deallocate (IWORK , stat=IALLOCATEstatus)
deallocate ( WORK , stat=IALLOCATEstatus)
deallocate (ATOL, stat=IALLOCATEstatus)
if(allocated(rtol)) deallocate (RTOL, stat=IALLOCATEstatus) !!! this is line 31134

I get an error (whether or not I check for allocated(rtol))

free(): invalid pointer

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0 0x7f99d22cad01 in ???
#1 0x7f99d22c9ed5 in ???
#2 0x7f99d1f9420f in ???
#3 0x7f99d1f9418b in ???
#4 0x7f99d1f73858 in ???
#5 0x7f99d1fde3ed in ???
#6 0x7f99d1fe647b in ???
#7 0x7f99d1fe7cab in ???
#8 0x55a74f9ee098 in stiffr_
at /home/me/DEVELOPMENT/HLINEARRADAUtst/ft185.f:31134

gdb complains about a missing raise.c file

free(): invalid pointer

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) l
45 in ../sysdeps/unix/sysv/linux/raise.c

Any ideas???
 
Could you try allocating and deallocating in the same routine? That way you won't have to check if something has been allocated.
 
It is being done in the same routine. Between allocating and deallocating I'm only calling
a routine with the allocated arrays and their dimensions as arguments. This routine does not change the array dimensions, so I am really puzzled.
 
Is this on the first or second time the code is invoked? Are the allocatable arrays passed in or are they local to the routine? I can see this happening, the second time it is invoked if the allocatable arrays are passed in.
 
This is the first time the code is invoked, but the S/R to which the allocated arrays are passed as arguments along with their dimensions is called multiple times(330 times). Interestingly enough it's on the last time the crash occurs...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top