From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31104 invoked by alias); 16 Nov 2011 16:44:12 -0000 Received: (qmail 31096 invoked by uid 22791); 16 Nov 2011 16:44:11 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Nov 2011 16:43:55 +0000 From: "stefano.borini at ferrara dot linux.it" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51175] New: Memory Leak with Transfer intrinsic Date: Wed, 16 Nov 2011 16:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: stefano.borini at ferrara dot linux.it X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg01678.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: stefano.borini@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