Plug memory leak in attribute target_clones
authorBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Thu, 3 Nov 2022 20:52:51 +0000 (21:52 +0100)
committerBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Sun, 6 Nov 2022 00:53:20 +0000 (01:53 +0100)
It looks like there was some memory leak in the handling
of attribute target_clones.

Ok for trunk if testing passes?

gcc/ChangeLog:

* multiple_target.cc (expand_target_clones): Free memory.

Signed-off-by: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
gcc/multiple_target.cc

index 67866a7..77e0f21 100644 (file)
@@ -390,19 +390,23 @@ expand_target_clones (struct cgraph_node *node, bool definition)
   for (i = 0; i < attrnum; i++)
     {
       char *attr = attrs[i];
-      char *suffix = XNEWVEC (char, strlen (attr) + 1);
 
-      create_new_asm_name (attr, suffix);
       /* Create new target clone.  */
       tree attributes = make_attribute ("target", attr,
                                        DECL_ATTRIBUTES (node->decl));
 
+      char *suffix = XNEWVEC (char, strlen (attr) + 1);
+      create_new_asm_name (attr, suffix);
       cgraph_node *new_node = create_target_clone (node, definition, suffix,
                                                   attributes);
+      XDELETEVEC (suffix);
       if (new_node == NULL)
-       return false;
+       {
+         XDELETEVEC (attrs);
+         XDELETEVEC (attr_str);
+         return false;
+       }
       new_node->local = false;
-      XDELETEVEC (suffix);
 
       decl2_v = new_node->function_version ();
       if (decl2_v != NULL)