From patchwork Tue Feb 26 21:22:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 223403 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 C58B42C0084 for ; Wed, 27 Feb 2013 08:22:48 +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=1362518569; 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=DLtarKyhkuWwKCJL51Kz gY8v1fQ=; b=aW0/X9DPn+R1i+SIlgZ+b0pAvDgF/HAYGucCNr6DFgp1m4YfGRwP s6V1uAWbEpsQf0xmfvQawOTdXDrL/MI4CVjB84q7zK8yZ3k/3/X6enfF3VQxF3Hq h3BbLykSObd5Jix46eVtcTRpvObj77mUpzLEKw4EiJ3g64Y+nkJyb10= 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=uGWpDY7oPGLRM69s+O8ZuFF84R1ks05UD3eXCGCWrXKFdLhJ1jZFhIwWCNGlms DiEectOWNDshcnt/ar//XDPNPLWHTNucvfi2EZfBnyIYBtPOrtMOIAAfn0bQ9Fai SFoIMNwqMfi6PqCln6QuDrX3+yLmIVFxOC+ovHX8PErlA=; Received: (qmail 26410 invoked by alias); 26 Feb 2013 21:22:39 -0000 Received: (qmail 26402 invoked by uid 22791); 26 Feb 2013 21:22:38 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, 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; Tue, 26 Feb 2013 21:22:33 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1QLMVud014210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Feb 2013 16:22:32 -0500 Received: from zalov.cz (vpn1-7-146.ams2.redhat.com [10.36.7.146]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1QLMUW8017789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Feb 2013 16:22:31 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r1QLMT0N020282; Tue, 26 Feb 2013 22:22:29 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1QLMSCe020281; Tue, 26 Feb 2013 22:22:28 +0100 Date: Tue, 26 Feb 2013 22:22:28 +0100 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix memory leaks in incpath.c Message-ID: <20130226212228.GD12913@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! Another file with memory leaks. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-02-26 Jakub Jelinek * incpath.c (add_standard_paths): Use reconcat instead of concat where appropriate and avoid leaking memory. Jakub --- gcc/incpath.c.jj 2013-01-11 09:02:35.000000000 +0100 +++ gcc/incpath.c 2013-02-26 15:11:23.676815551 +0100 @@ -149,12 +149,17 @@ add_standard_paths (const char *sysroot, { char *str = concat (iprefix, p->fname + len, NULL); if (p->multilib == 1 && imultilib) - str = concat (str, dir_separator_str, imultilib, NULL); + str = reconcat (str, str, dir_separator_str, + imultilib, NULL); else if (p->multilib == 2) { if (!imultiarch) - continue; - str = concat (str, dir_separator_str, imultiarch, NULL); + { + free (str); + continue; + } + str = reconcat (str, str, dir_separator_str, + imultiarch, NULL); } add_path (str, SYSTEM, p->cxx_aware, false); } @@ -183,6 +188,7 @@ add_standard_paths (const char *sysroot, && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len)) { static const char *relocated_prefix; + char *ostr; /* If this path starts with the configure-time prefix, but the compiler has been relocated, replace it with the run-time prefix. The run-time exec prefix @@ -198,22 +204,27 @@ add_standard_paths (const char *sysroot, = make_relative_prefix (dummy, cpp_EXEC_PREFIX, cpp_PREFIX); + free (dummy); } - str = concat (relocated_prefix, - p->fname + cpp_PREFIX_len, - NULL); - str = update_path (str, p->component); + ostr = concat (relocated_prefix, + p->fname + cpp_PREFIX_len, + NULL); + str = update_path (ostr, p->component); + free (ostr); } else str = update_path (p->fname, p->component); if (p->multilib == 1 && imultilib) - str = concat (str, dir_separator_str, imultilib, NULL); + str = reconcat (str, str, dir_separator_str, imultilib, NULL); else if (p->multilib == 2) { if (!imultiarch) - continue; - str = concat (str, dir_separator_str, imultiarch, NULL); + { + free (str); + continue; + } + str = reconcat (str, str, dir_separator_str, imultiarch, NULL); } add_path (str, SYSTEM, p->cxx_aware, false);