http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51175
Bug #: 51175 Summary: Memory Leak with Transfer intrinsic Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: stefano.bor...@ferrara.linux.it Hello, I am using gfortran 4.6.2 on MacOSX 10.7. It appears that this code involving transfer generates a memory leak module LeakModule implicit none contains subroutine Leaking(stringdata, string) character(len=1), intent(in) :: stringdata(:) character(len=*), intent(out) :: string character(len=1) :: singleChar(1) !integer :: numChars !numChars = size(transfer(stringdata,singleChar)) !string = '' string = transfer(stringdata, string) !string(numChars+1:) = ' ' end subroutine subroutine Foo() character(len=1) :: stringdata(3) character(len=20) :: outstring stringdata(1) = 'H' stringdata(2) = 'i' stringdata(3) = '!' call Leaking(stringdata, outstring) print *, outstring end subroutine end module program test use LeakModule call foo() end According to the produced assembler, malloc gets called inside the Leaking routine, but the asm of the caller never issues a free of that allocated memory. The same happens even if the string is a local variable with specified len. The commented code (calculating the size of the data involved) correctly issues one malloc and one free. Thanks