Let commands free "name"
[deliverable/binutils-gdb.git] / gdb / value.c
index 8e22ac7f8c1bce79605e7679ea2a4a3d5d214314..57e62b9175f4addbc3596b7ddfe92c5f7de745b1 100644 (file)
@@ -2421,31 +2421,19 @@ function_command (const char *command, int from_tty)
   /* Do nothing.  */
 }
 
-/* Clean up if an internal function's command is destroyed.  */
-static void
-function_destroyer (struct cmd_list_element *self, void *ignore)
-{
-  xfree ((char *) self->name);
-}
-
 /* Helper function that does the work for add_internal_function.  */
 
 static struct cmd_list_element *
 do_add_internal_function (const char *name, const char *doc,
                          internal_function_fn handler, void *cookie)
 {
-  struct cmd_list_element *cmd;
   struct internal_function *ifn;
   struct internalvar *var = lookup_internalvar (name);
 
   ifn = create_internal_function (name, handler, cookie);
   set_internalvar_function (var, ifn);
 
-  cmd = add_cmd (xstrdup (name), no_class, function_command, (char *) doc,
-                &functionlist);
-  cmd->destroyer = function_destroyer;
-
-  return cmd;
+  return add_cmd (name, no_class, function_command, doc, &functionlist);
 }
 
 /* See value.h.  */
@@ -2460,13 +2448,16 @@ add_internal_function (const char *name, const char *doc,
 /* See value.h.  */
 
 void
-add_internal_function (const char *name, gdb::unique_xmalloc_ptr<char> &&doc,
+add_internal_function (gdb::unique_xmalloc_ptr<char> &&name,
+                      gdb::unique_xmalloc_ptr<char> &&doc,
                       internal_function_fn handler, void *cookie)
 {
   struct cmd_list_element *cmd
-    = do_add_internal_function (name, doc.get (), handler, cookie);
+    = do_add_internal_function (name.get (), doc.get (), handler, cookie);
   doc.release ();
   cmd->doc_allocated = 1;
+  name.release ();
+  cmd->name_allocated = 1;
 }
 
 /* Update VALUE before discarding OBJFILE.  COPIED_TYPES is used to
This page took 0.025525 seconds and 4 git commands to generate.