From d44f56f2b2d4f0a827ba6f08aebc715786225c6f Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 9 Feb 2021 09:57:04 +0100 Subject: [PATCH] ICF: fix memory leak gcc/ChangeLog: PR ipa/99003 * ipa-icf.c (sem_item::add_reference): Fix memory leak when a reference exists. --- gcc/ipa-icf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index 435f567d72e..687ad8d45b7 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -165,8 +165,11 @@ sem_item::add_reference (ref_map *refs, unsigned index = reference_count++; bool existed; - vec &v - = refs->get_or_insert (new sem_usage_pair (target, index), &existed); + sem_usage_pair *pair = new sem_usage_pair (target, index); + vec &v = refs->get_or_insert (pair, &existed); + if (existed) + delete pair; + v.safe_push (this); bitmap_set_bit (target->usage_index_bitmap, index); refs_set.add (target->node); -- 2.30.2