2 ! Tests the fix for PR41478, in which double frees would occur because
3 ! transformational intrinsics did not copy the allocatable components
4 ! so that they were (sometimes) freed twice on exit. In addition,
5 ! The original allocatable components of a1 were not freed, so that
6 ! memory leakage occurred.
8 ! Contributed by Juergen Reuter <reuter@physik.uni-freiburg.de>
11 integer, dimension(:), allocatable
:: entry
18 ! This is the reported problem.
21 type(container_t
), dimension(4) :: a1
, a2
, a3
24 allocate (a1(i
)%entry (2), a2(i
)%entry (2), a3(i
)%entry (2))
32 a1(1:2) = pack (a2
, [.true
., .false
., .true
., .false
.])
34 if (.not
.allocated (a1(i
)%entry)) call abort
36 if (any (a1(i
)%entry .ne
. [1,2])) call abort
38 if (any (a1(i
)%entry .ne
. [3,4])) call abort
44 a1
= unpack (a1
, [.true
., .true
., .false
., .false
.], a3
)
45 if (any (a1
%index
.ne
. [1,3,3,4])) call abort
47 if (.not
.allocated (a1(i
)%entry)) call abort
49 if (any (a1(i
)%entry .ne
. [4,5])) call abort
51 if (any (a1(i
)%entry .ne
. [3,4])) call abort
56 ! Other all transformational intrinsics display it. Having done
57 ! PACK and UNPACK, just use TRANSPOSE as a demonstrator.
60 type(container_t
), dimension(2,2) :: a1
, a2
64 allocate (a1(i
, j
)%entry (2), a2(i
, j
)%entry (2))
65 a1(i
, j
)%entry = [i
,j
]
66 a2(i
, j
)%entry = [i
,j
]
67 a1(i
,j
)%index
= j
+ (i
- 1)*2
68 a2(i
,j
)%index
= j
+ (i
- 1)*2
74 if (a1(i
,j
)%index
.ne
. i
+ (j
- 1)*2) call abort
75 if (any (a1(i
,j
)%entry .ne
. [j
,i
])) call abort