From patchwork Tue Apr 14 08:14:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 461080 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 56B27140276 for ; Tue, 14 Apr 2015 18:14:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=RnN7a08e; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=ujV/mB6v2eq8wpOznLvf/x2O9l/wqG5G3xH+dWaLlSE QlCNJTMgizii/IJ5fNBd0lDF2+yjg70oxUESi059fp2U1DwwVVcBBO8w5hx1hPxS dd28uP5QWtc/LAoUStSKoo/lZLLgCayam8Fn2xhAxEIm+xIJMcxQFFcr/JWkKmtw = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=rhHFEELO59pEtVlQpPDQp8DHD+M=; b=RnN7a08e+Tg6BIp37 xCkqTadvbV7DeR+snFedaZAD9//tH/TZPR4RpgkUn/RwDOIpo3Yoma02aLg9M5iR 0J4CQQt9PHXZyIEwVls1PiirYlt8UzYwwTfcK5xQt+wYZXcbEdSZYe6axDtAVN7j jREae3qrt7zZMiJZQO01KTGtF8= Received: (qmail 65506 invoked by alias); 14 Apr 2015 08:14:10 -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 65496 invoked by uid 89); 14 Apr 2015 08:14:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 14 Apr 2015 08:14:09 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9CCD8ABA2; Tue, 14 Apr 2015 08:14:06 +0000 (UTC) Message-ID: <552CCC4E.7090208@suse.cz> Date: Tue, 14 Apr 2015 10:14:06 +0200 From: =?UTF-8?B?TWFydGluIExpxaFrYQ==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: GCC Patches CC: Jan Hubicka Subject: [PATCH] Fix memory leak in IPA passes X-IsSubscribed: yes Hello. As originally reported by Andi Kleen, following patch fix memory leaks that can be seen in IPA ICF and IPA CP. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Moreover, with patch applied, we can build Firefox and Linux kernel on ppc64le-linux-gnu. Ready for both trunk and 5 branch? Thanks, Martin From 5258b6a07d01c632976c3a5c3c5e47da3a9965e3 Mon Sep 17 00:00:00 2001 From: mliska Date: Mon, 13 Apr 2015 13:15:59 +0200 Subject: [PATCH] Fix IPA memory leaks. gcc/ChangeLog: 2015-04-13 Martin Liska * ipa-cp.c (ipcp_driver): Release prev_edge_clone. * ipa-icf.c (sem_item_optimizer::subdivide_classes_by_sensitive_refs): Release symbol_compare_collection. * ipa-reference.c: Add TODO that a vector should be released. --- gcc/ipa-cp.c | 1 + gcc/ipa-icf.c | 26 ++++++++++++++++++++------ gcc/ipa-reference.c | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index bfe4821..3824029 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -4493,6 +4493,7 @@ ipcp_driver (void) /* Free all IPCP structures. */ free_toporder_info (&topo); next_edge_clone.release (); + prev_edge_clone.release (); symtab->remove_edge_removal_hook (edge_removal_hook_holder); symtab->remove_edge_duplication_hook (edge_duplication_hook_holder); ipa_free_all_structures_after_ipa_cp (); diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index b902373..a72ac2e 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -2712,6 +2712,9 @@ sem_item_optimizer::subdivide_classes_by_equality (bool in_wpa) unsigned sem_item_optimizer::subdivide_classes_by_sensitive_refs () { + typedef hash_map , + symbol_compare_hashmap_traits> subdivide_hash_map; + unsigned newly_created_classes = 0; for (hash_table ::iterator it = m_classes.begin (); @@ -2726,8 +2729,7 @@ sem_item_optimizer::subdivide_classes_by_sensitive_refs () if (c->members.length() > 1) { - hash_map , - symbol_compare_hashmap_traits> split_map; + subdivide_hash_map split_map; for (unsigned j = 0; j < c->members.length (); j++) { @@ -2735,10 +2737,15 @@ sem_item_optimizer::subdivide_classes_by_sensitive_refs () symbol_compare_collection *collection = new symbol_compare_collection (source_node->node); - vec *slot = &split_map.get_or_insert (collection); + bool existed; + vec *slot = &split_map.get_or_insert (collection, + &existed); gcc_checking_assert (slot); slot->safe_push (source_node); + + if (existed) + delete collection; } /* If the map contains more than one key, we have to split the map @@ -2747,9 +2754,8 @@ sem_item_optimizer::subdivide_classes_by_sensitive_refs () { bool first_class = true; - hash_map , - symbol_compare_hashmap_traits>::iterator it2 = split_map.begin (); - for (; it2 != split_map.end (); ++it2) + for (subdivide_hash_map::iterator it2 = split_map.begin (); + it2 != split_map.end (); ++it2) { congruence_class *new_cls; new_cls = new congruence_class (class_id++); @@ -2772,6 +2778,14 @@ sem_item_optimizer::subdivide_classes_by_sensitive_refs () } } } + + /* Release memory. */ + for (subdivide_hash_map::iterator it2 = split_map.begin (); + it2 != split_map.end (); ++it2) + { + delete (*it2).first; + (*it2).second.release (); + } } } diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 219a9b3..a420cb2 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -150,6 +150,7 @@ static struct cgraph_node_hook_list *node_removal_hook_holder; Indexed by UID of call graph nodes. */ static vec ipa_reference_vars_vector; +/* TODO: find a place where we should release the vector. */ static vec ipa_reference_opt_sum_vector; /* Return the ipa_reference_vars structure starting from the cgraph NODE. */ -- 2.1.4