ICF: fix memory leak
authorMartin Liska <mliska@suse.cz>
Tue, 9 Feb 2021 08:57:04 +0000 (09:57 +0100)
committerMartin Liska <mliska@suse.cz>
Wed, 10 Feb 2021 08:25:38 +0000 (09:25 +0100)
gcc/ChangeLog:

PR ipa/99003
* ipa-icf.c (sem_item::add_reference): Fix memory leak when
a reference exists.

gcc/ipa-icf.c

index 435f567d72e6a3ceae193587ff21f66361891a95..687ad8d45b70c5b1fea66f6f6db23b1a11ab205d 100644 (file)
@@ -165,8 +165,11 @@ sem_item::add_reference (ref_map *refs,
   unsigned index = reference_count++;
   bool existed;
 
-  vec<sem_item *> &v
-    = refs->get_or_insert (new sem_usage_pair (target, index), &existed);
+  sem_usage_pair *pair = new sem_usage_pair (target, index);
+  vec<sem_item *> &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);