From patchwork Mon Jan 21 14:36:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 214185 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 BAAF92C008D for ; Tue, 22 Jan 2013 01:36:38 +1100 (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=1359383799; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=r1QgXBXIlmAPolfr6Gpa t+M7xp0=; b=kwoRiD/04M+87tQq/1TZp4m00doOcRJ0A2iQwfSDucr8P6ki04i1 uF6f2Xd1pEHIpEV4cSmOW+dpWb3uBbpLOSOv6cF04ZYL8BiOnaDxPDsMzL1CtaNd gN3OjM+YaJhS3+nAqLT/w7NloLddY17fMSWG8i7qgtw5v994nD48MY4= 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:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=aUBIiq3Cb96ph1MBnTH286zQRYuzJZzenSrMghHBy08/MGhm05KSm1trEflqul 3zx1bZWq4yk8rbEb7sgTuimANJa4zlvMpeRSrwcSbXjRXHXYDVIjOppXNFUgBuVo wjaGl40FIwB+vYYaxmBnZEQpDXnbOA5zaFTZ2Drbu9dro=; Received: (qmail 17670 invoked by alias); 21 Jan 2013 14:36:34 -0000 Received: (qmail 17565 invoked by uid 22791); 21 Jan 2013 14:36:33 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Jan 2013 14:36:26 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0LEaQeh028957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Jan 2013 09:36:26 -0500 Received: from zalov.redhat.com (vpn1-6-248.ams2.redhat.com [10.36.6.248]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0LEaOF0021547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 21 Jan 2013 09:36:25 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r0LEaNXB029676; Mon, 21 Jan 2013 15:36:23 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r0LEaN4a029675; Mon, 21 Jan 2013 15:36:23 +0100 Date: Mon, 21 Jan 2013 15:36:23 +0100 From: Jakub Jelinek To: Vladimir Makarov Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix init_reload memory leak Message-ID: <20130121143623.GN7269@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! While working on the multiversioning patch I've just posted, I've noticed that on say: void foo (); void foo () __attribute__((target ("avx"))); void foo () __attribute__((target ("default"))); __attribute__((target ("default"))) void foo () { } __attribute__((target ("avx"))) void foo () { } void (*fn) () = foo; we leak memory, because init_reload is called several times (due to target attribute) and it never destroys reload_obstack already created before initializing a new one. Fixed by initializing it just once. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-21 Jakub Jelinek * reload1.c (init_reload): Only initialize reload_obstack during the first call. Jakub --- gcc/reload1.c.jj 2013-01-11 09:03:17.000000000 +0100 +++ gcc/reload1.c 2013-01-21 12:47:01.091040655 +0100 @@ -468,8 +468,11 @@ init_reload (void) } /* Initialize obstack for our rtl allocation. */ - gcc_obstack_init (&reload_obstack); - reload_startobj = XOBNEWVAR (&reload_obstack, char, 0); + if (reload_startobj == NULL) + { + gcc_obstack_init (&reload_obstack); + reload_startobj = XOBNEWVAR (&reload_obstack, char, 0); + } INIT_REG_SET (&spilled_pseudos); INIT_REG_SET (&changed_allocation_pseudos);