From patchwork Tue Jan 21 01:06:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1226198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517832-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=xtKYwZ4A; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ua8qgfFx; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 481r3x5fzKz9sRK for ; Tue, 21 Jan 2020 12:07:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=vcEt0y4Glw58yNxL cs8c8d5arQJvoVOOh4X5WOFmkIqdbxrdNwrv4lKxMl5+GfF82K3ZbN9GACF/wKgh ANt4t0N42MsfsXffmXiDxcPb5zZ5utzCbmwnnzEThQRKT+GCtHMP+u3NlpB2JELN 1D0oXjIrqOEjHsZSi0n2RzINphQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=4NGusb5khFY8KfhOfO3dVn Xtquk=; b=xtKYwZ4Ae1EN3Koete5mRtJJ/SIlL54tWyEudfSBc6ETqt7e2MY9kv /iYCTEfoMBFBZbc7FgQZH0HYyy/tWjkpSUt9jd8UIKXDsgkHu9K0SStBOQkmvK7e xHiFA+j6w9HIbSbTDAqPUa5zre0igNTaO97yBqudiKkuLb25Ee6mk= Received: (qmail 90206 invoked by alias); 21 Jan 2020 01:07:15 -0000 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 Received: (qmail 90189 invoked by uid 89); 21 Jan 2020 01:07:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=sk:cp_lite, get_mapped_args X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2020 01:07:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579568824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RibCkjxO/qVn+1Fp6Z1+0EPVxOu4cwRKYdIAcP2nlhI=; b=Ua8qgfFxDGGiSezLE1zQ0yJnjRCkBc5xcA63BQg1hK/Jd8Qm+1YygX44MiudcUWKhkYZRY eWySPJisheV9owYgOxaxF04FmfZfOFj++pDGhosEBswBDQenGJNzkjFKfsWPDzh0geFGnP JJ6UqpzwxQlN9Lp8aPbrhxp7zy/ACmA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-122-a9dBJtY-NC69HEyj5-J8yg-1; Mon, 20 Jan 2020 20:07:01 -0500 Received: by mail-qv1-f72.google.com with SMTP id g15so606782qvq.20 for ; Mon, 20 Jan 2020 17:07:01 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id r10sm16330594qkm.23.2020.01.20.17.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 17:07:00 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix a couple of memory leaks in the C++ frontend Date: Mon, 20 Jan 2020 20:06:54 -0500 Message-Id: <20200121010654.3414484-1-ppalka@gcc.gnu.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com The leak in get_mapped_args is due to auto_vec not properly supporting destructible elements, in that auto_vec's destructor doesn't call the destructors of its elements. Successfully bootstrapped and regtested on x86_64-pc-linux-gnu, OK to commit? gcc/cp/ChangeLog: * constraint.cc (get_mapped_args): Avoid using auto_vec as a vector element. Release the vectors inside the lists vector. * parser.c (cp_literal_operator_id): Free the buffer. --- gcc/cp/constraint.cc | 7 ++++--- gcc/cp/parser.c | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 128ab8ae0b2..823604afb89 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2431,7 +2431,7 @@ get_mapped_args (tree map) list. Note that the list will be sparse (not all arguments supplied), but instantiation is guaranteed to only use the parameters in the mapping, so null arguments would never be used. */ - auto_vec< auto_vec > lists (count); + auto_vec< vec > lists (count); lists.quick_grow_cleared (count); for (tree p = map; p; p = TREE_CHAIN (p)) { @@ -2440,7 +2440,7 @@ get_mapped_args (tree map) template_parm_level_and_index (TREE_VALUE (p), &level, &index); /* Insert the argument into its corresponding position. */ - auto_vec &list = lists[level - 1]; + vec &list = lists[level - 1]; if (index >= (int)list.length ()) list.safe_grow_cleared (index + 1); list[index] = TREE_PURPOSE (p); @@ -2450,11 +2450,12 @@ get_mapped_args (tree map) tree args = make_tree_vec (lists.length ()); for (unsigned i = 0; i != lists.length (); ++i) { - auto_vec &list = lists[i]; + vec &list = lists[i]; tree level = make_tree_vec (list.length ()); for (unsigned j = 0; j < list.length(); ++j) TREE_VEC_ELT (level, j) = list[j]; SET_TMPL_ARGS_LEVEL (args, i + 1, level); + list.release (); } SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (args, 0); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c5f9798a5ed..e1e27a574f1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15344,6 +15344,7 @@ cp_literal_operator_id (const char* name) + strlen (name) + 10); sprintf (buffer, UDLIT_OP_ANSI_FORMAT, name); identifier = get_identifier (buffer); + free (buffer); return identifier; }