From patchwork Fri May 11 08:15:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 158459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A82EFB6FC3 for ; Fri, 11 May 2012 18:16:48 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1337329008; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=NSltIdz 1Mh0CgF0eF/1fStsB6XE=; b=i6gi5boSPmbFYjSePp9/x1v9tEgJ4SCZQPcaw6H OPfD7I2S8hBSsRDHakEjZQy2Rs/1H+JJCN+xft6c3GpmUKnit1CT4UFtBErIDng+ cw4STTIIJ29GJBQuNJuEURxJX0Zt1hnlCHQWDab1P0R2THd/DPLoCz7D83DRfngJ uj7s= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=R6ULG0tu/+kgR1zlAa584Bd95q9N/5JsG1LZu+rNSAsaSai9gTJkRjJ/WNoOBt HrgshCogqckOZIwbTEYzDw9WQEz3/B++8fWgR5QlJ1NABU1s6X7b0Sohp1+CVSqb hVM53aOiBEEGQM/tPb3HR0z7S3G5lbT6p+G7ChKJ6F2og=; Received: (qmail 27456 invoked by alias); 11 May 2012 08:16:18 -0000 Received: (qmail 27422 invoked by uid 22791); 11 May 2012 08:16:12 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_BG X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 May 2012 08:15:55 +0000 Received: from [192.168.178.22] (port-92-204-48-84.dynamic.qsc.de [92.204.48.84]) by mx01.qsc.de (Postfix) with ESMTP id BE876804D; Fri, 11 May 2012 10:15:48 +0200 (CEST) Message-ID: <4FACCAB2.9040401@net-b.de> Date: Fri, 11 May 2012 10:15:46 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120328 Thunderbird/11.0.1 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran, committed] PR53310 - Fix multi-malloc memory leak in EOSHIFT Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I have committed the attached patch as obvious. libgfortran (since GCC 4.5) allocates the memory rank()-times instead of only once in eoshift2. For the test case of the PR, gfortran leaked 6 MB per call! Build and regtested on x86-64-linux and comitted as Rev. 187395 to the 4.8 trunk. I intent to backport the patch, but I have not yet decided whether it will be down to 4.5 or not. Tobias PS: In the ChangeLog I have converted some spaces into tabs. Index: libgfortran/intrinsics/eoshift2.c =================================================================== --- libgfortran/intrinsics/eoshift2.c (revision 187394) +++ libgfortran/intrinsics/eoshift2.c (working copy) @@ -77,6 +77,10 @@ eoshift2 (gfc_array_char *ret, const gfc_array_cha ret->offset = 0; ret->dtype = array->dtype; + + /* xmalloc allocates a single byte for zero size. */ + ret->base_addr = xmalloc (size * arraysize); + for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++) { index_type ub, str; @@ -90,10 +94,6 @@ eoshift2 (gfc_array_char *ret, const gfc_array_cha * GFC_DESCRIPTOR_STRIDE(ret,i-1); GFC_DIMENSION_SET(ret->dim[i], 0, ub, str); - - /* xmalloc allocates a single byte for zero size. */ - ret->base_addr = xmalloc (size * arraysize); - } } else if (unlikely (compile_options.bounds_check)) Index: libgfortran/ChangeLog =================================================================== --- libgfortran/ChangeLog (revision 187394) +++ libgfortran/ChangeLog (working copy) @@ -1,17 +1,23 @@ +2012-05-11 Tobias Burnus + + PR fortran/53310 + * intrinsics/eoshift2.c (eoshift2): Do not leak + memory by allocating it in the loop. + 2012-05-05 Janne Blomqvist - * config.h.in: Regenerated. - * configure: Regenerated. - * configure.ac: Add checks for getegid and __secure_getenv. - * io/unix.c (P_tmpdir): Fallback definition for macro. - (tempfile_open): New function. - (tempfile): Use secure_getenv, call tempfile_open to try each - directory in turn. - * libgfortran.h (DEFAULT_TMPDIR): Remove macro. - (secure_getenv): New macro/prototype. - * runtime/environ.c (secure_getenv): New function. - (variable_table): Rename GFORTRAN_TMPDIR to TMPDIR. - * runtime/main.c (find_addr2line): Use secure_getenv. + * config.h.in: Regenerated. + * configure: Regenerated. + * configure.ac: Add checks for getegid and __secure_getenv. + * io/unix.c (P_tmpdir): Fallback definition for macro. + (tempfile_open): New function. + (tempfile): Use secure_getenv, call tempfile_open to try each + directory in turn. + * libgfortran.h (DEFAULT_TMPDIR): Remove macro. + (secure_getenv): New macro/prototype. + * runtime/environ.c (secure_getenv): New function. + (variable_table): Rename GFORTRAN_TMPDIR to TMPDIR. + * runtime/main.c (find_addr2line): Use secure_getenv. 2012-04-22 Tobias Burnus @@ -479,24 +485,24 @@ 2012-03-15 Janne Blomqvist - PR libfortran/52434 - PR libfortran/48878 - PR libfortran/38199 - * io/unit.c (get_internal_unit): Default to ROUND_UNSPECIFIED. - (init_units): Likewise. - * io/write_float.def (determine_precision): New function. - (output_float): Take into account buffer with %f format, no need - for our own rounding if unspecified or processor specified - rounding. - (DTOA): Simplify format string, add parameters. - (FDTOA): New macros similar to DTOA, but using %f format. - (OUTPUT_FLOAT_FMT_G): Stack allocate newf, determine correct - precision and fill buffer. - (EN_PREC): New macro. - (determine_en_precision): New function. - (WRITE_FLOAT): For G format, move buffer filling into - output_float_FMT_G, use FDTOA for F format. - (write_float): Increase buffer due to F format. + PR libfortran/52434 + PR libfortran/48878 + PR libfortran/38199 + * io/unit.c (get_internal_unit): Default to ROUND_UNSPECIFIED. + (init_units): Likewise. + * io/write_float.def (determine_precision): New function. + (output_float): Take into account buffer with %f format, no need + for our own rounding if unspecified or processor specified + rounding. + (DTOA): Simplify format string, add parameters. + (FDTOA): New macros similar to DTOA, but using %f format. + (OUTPUT_FLOAT_FMT_G): Stack allocate newf, determine correct + precision and fill buffer. + (EN_PREC): New macro. + (determine_en_precision): New function. + (WRITE_FLOAT): For G format, move buffer filling into + output_float_FMT_G, use FDTOA for F format. + (write_float): Increase buffer due to F format. 2012-03-14 Rainer Orth