From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway20.websitewelcome.com (gateway20.websitewelcome.com [192.185.65.13]) by sourceware.org (Postfix) with ESMTPS id 996D839B8C26 for ; Wed, 28 Apr 2021 01:01:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 996D839B8C26 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 1CB11400F8F3E for ; Tue, 27 Apr 2021 19:50:21 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bYaGlL9NNPkftbYaGlTFgU; Tue, 27 Apr 2021 20:01:44 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uCLSzQSRJyeq8IPwGJiMR4XXBbItxO8DRLt0LeJE42w=; b=qZwm2UWktIJXU6125Nu6iQKJMn Qx5HRKPsszhMfbRd8tK3SN+qHG7+b9cYBCrLhBVsYptkqrqljtMHrh1biMbIw5x3Jdtj7IIY4VSKe KZMlVz8qB9OlqC2ZKNYx5uQre; Received: from 97-122-70-176.hlrn.qwest.net ([97.122.70.176]:32966 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lbYaG-003tiR-8F; Tue, 27 Apr 2021 19:01:44 -0600 From: Tom Tromey To: gcc-patches@gcc.gnu.org Cc: Tom Tromey Subject: [PATCH v2 18/21] libcc1: fix a memory leak Date: Tue, 27 Apr 2021 19:01:16 -0600 Message-Id: <20210428010119.806184-19-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428010119.806184-1-tom@tromey.com> References: <20210428010119.806184-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.176 X-Source-L: No X-Exim-ID: 1lbYaG-003tiR-8F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-176.hlrn.qwest.net (localhost.localdomain) [97.122.70.176]:32966 X-Source-Auth: tom+tromey.com X-Email-Count: 19 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Apr 2021 01:01:48 -0000 libcc1 has a memory leak when calling fork_exec -- it allocates a new vector of arguments, but then does not free it anywhere. This patch changes this code to use std::vector instead. Note that the previous code tried to avoid bad_alloc. I don't believe this is very important. For one thing, plenty of other allocations do not bother with this. libcc1/ChangeLog 2021-04-27 Tom Tromey * gdbctx.hh (do_compile): Use std::vector. --- libcc1/ChangeLog | 4 ++++ libcc1/gdbctx.hh | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libcc1/gdbctx.hh b/libcc1/gdbctx.hh index 4a48381f2b4a..4d2488344bc8 100644 --- a/libcc1/gdbctx.hh +++ b/libcc1/gdbctx.hh @@ -308,15 +308,11 @@ namespace cc1_plugin self->add_callbacks (); - char **argv = new (std::nothrow) char *[self->args.size () + 1]; - if (argv == NULL) - return 0; - + std::vector argv (self->args.size () + 1); for (unsigned int i = 0; i < self->args.size (); ++i) argv[i] = const_cast (self->args[i].c_str ()); - argv[self->args.size ()] = NULL; - return self->fork_exec (argv, fds, stderr_fds); + return self->fork_exec (argv.data (), fds, stderr_fds); } static int -- 2.26.2