Silverfrost Forums

Welcome to our forums

DEALLOCATE

7 Nov 2013 10:20 (Edited: 11 Nov 2013 7:34) #13286

The following program allocates memory to two arrays ia and ib. It then attempts to deallocate the memory in ib, but after (admittedly confusingly) renaming it ia in the USE statement. However, it is actually ia that gets deallocated. That seems to me to be a bug.

! This program appears to deallocate the wrong array.
MODULE m1
 INTEGER, DIMENSION(:), ALLOCATABLE :: ia
 INTEGER, DIMENSION(:), ALLOCATABLE :: ib
END MODULE m1
MODULE m2
CONTAINS
 SUBROUTINE s1 ()
  USE m1, ONLY: ia
   ALLOCATE (ia(2))
 END SUBROUTINE s1
 SUBROUTINE s2 ()
  USE m1, ONLY: ib
   ALLOCATE (ib(2))
 END SUBROUTINE s2
 SUBROUTINE s3 ()
  USE m1, ONLY: ia=>ib
   DEALLOCATE (ia)
 END SUBROUTINE s3
END MODULE m2
PROGRAM p
  USE m1
  USE m2
  CALL s1 ()
  CALL s2 ()
  CALL s3 ()
  PRINT *, ALLOCATED(ia),ALLOCATED(ib)
END PROGRAM p
7 Nov 2013 5:36 #13291

This looks like a bug to me too.

11 Nov 2013 10:18 #13306

I agree. I have logged it for investigation.

3 Apr 2014 10:48 #13922

This bug has now been fixed for the next release.

11 Feb 2017 12:16 #18831

My notes indicate that this problem was fixed in version 7.10, but it seems to have resurfaced: I'm using version 8.05. I don't know whether the problem occurred in 7.20 or 8.00.

11 Feb 2017 8:43 #18832

I will take another look at this as soon as I can.

18 Feb 2017 9:17 #18847

It turns out that this is a known regression. The original fix has been removed because it caused a more serious problem elsewhere.

For now at least, I suggest that you avoid using a name for a local variable (ia in this case) when this name has already been used in a parent module.

SUBROUTINE s3 () 
  USE m1, ONLY: iaa=>ib 
   DEALLOCATE (iaa) 
 END SUBROUTINE s3 
Please login to reply.