https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106750
anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-08-30 Ever confirmed|0 |1 Keywords| |wrong-code Status|UNCONFIRMED |NEW CC| |anlauf at gcc dot gnu.org --- Comment #1 from anlauf at gcc dot gnu.org --- Confirmed. The memory leak comes from not deallocating the temporary when we have a vector index. OTOH using an equivalent array constructor creates the necessary free()'s, as can be seen from the dump. Reduced testcase: program test implicit none type :: t integer, allocatable :: a(:) end type t integer, parameter :: n = 100 type(t), allocatable :: ts(:) integer :: j(n),i allocate(ts(1)) ts(1) = t([1,2,3]) do i=1,n j(i) = do_with_array([ts(1),ts(1)]) ! no leak ! j(i) = do_with_array( ts([1,1]) ) ! MEMORY LEAK end do print *, 'sum=',sum(j) deallocate(ts) contains integer function do_with_array(ts) result(l) type(t), intent(in) :: ts(:) l = 1 end function end program test