https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124780
Bug ID: 124780
Summary: Bugs found while testing the fix for PR100155
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: pault at gcc dot gnu.org
Target Milestone: ---
Created attachment 64144
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64144&action=edit
Regression free patch
Found by Harald Anlauf in reviewing the above PR:
program p
integer :: i
type :: t
integer, allocatable :: i(:)
end type
type (t), allocatable :: src(:), ans(:)
src = [t([1,2]), t([3,4])] ! Leaks memory 16 bytes in 2 blocks;
! familiar from PDT memory leaks :-(
ans = f(src)
do i = 1,2
print *, "src = ", src(i)%i, "ans = ",ans(i)%i
deallocate (ans(i)%i, src(i)%i)
enddo
deallocate (ans, src)
contains
function f(x) result(z)
class(t), intent(inout) :: x(:)
type(t) :: z (size(x))
class(t), allocatable :: a(:)
class(t), allocatable :: b(:)
allocate (a(size(x)))
select type (x)
type is (t)
a = x ! Mangles src and causes
! double free at line 12
end select
b = x
z = (b) ! ICE, without patch
end
end