public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 3/3] Remove cleanups from break-catch-syscall.c
Date: Wed, 18 Oct 2017 04:06:00 -0000	[thread overview]
Message-ID: <20171018040645.7212-3-tom@tromey.com> (raw)
In-Reply-To: <20171018040645.7212-1-tom@tromey.com>

This removes the remaining cleanups from break-catch-syscall.c by
storing temporary strings in a vector.

ChangeLog
2017-10-17  Tom Tromey  <tom@tromey.com>

	* break-catch-syscall.c (catch_syscall_completer): Use
	std::string, gdb::unique_xmalloc_ptr.
---
 gdb/ChangeLog             |  5 +++++
 gdb/break-catch-syscall.c | 35 ++++++++++++++++++-----------------
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 01e761ce37..2bbfee0ac4 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -560,9 +560,7 @@ catch_syscall_completer (struct cmd_list_element *cmd,
                          const char *text, const char *word)
 {
   struct gdbarch *gdbarch = get_current_arch ();
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
-  const char **group_list = NULL;
-  const char **syscall_list = NULL;
+  gdb::unique_xmalloc_ptr<const char *> group_list;
   const char *prefix;
   int i;
 
@@ -575,34 +573,37 @@ catch_syscall_completer (struct cmd_list_element *cmd,
   if (startswith (prefix, "g:") || startswith (prefix, "group:"))
     {
       /* Perform completion inside 'group:' namespace only.  */
-      group_list = get_syscall_group_names (gdbarch);
+      group_list.reset (get_syscall_group_names (gdbarch));
       if (group_list != NULL)
-	complete_on_enum (tracker, group_list, word, word);
+	complete_on_enum (tracker, group_list.get (), word, word);
     }
   else
     {
       /* Complete with both, syscall names and groups.  */
-      syscall_list = get_syscall_names (gdbarch);
-      group_list = get_syscall_group_names (gdbarch);
+      gdb::unique_xmalloc_ptr<const char *> syscall_list
+	(get_syscall_names (gdbarch));
+      group_list.reset (get_syscall_group_names (gdbarch));
+
+      const char **group_ptr = group_list.get ();
+
+      /* Hold on to strings while we're using them.  */
+      std::vector<std::string> holders;
 
       /* Append "group:" prefix to syscall groups.  */
-      for (i = 0; group_list[i] != NULL; i++)
+      for (i = 0; group_ptr[i] != NULL; i++)
 	{
-	  char *prefixed_group = xstrprintf ("group:%s", group_list[i]);
+	  std::string prefixed_group = string_printf ("group:%s",
+						      group_ptr[i]);
 
-	  group_list[i] = prefixed_group;
-	  make_cleanup (xfree, prefixed_group);
+	  group_ptr[i] = prefixed_group.c_str ();
+	  holders.push_back (prefixed_group);
 	}
 
       if (syscall_list != NULL)
-	complete_on_enum (tracker, syscall_list, word, word);
+	complete_on_enum (tracker, syscall_list.get (), word, word);
       if (group_list != NULL)
-	complete_on_enum (tracker, group_list, word, word);
+	complete_on_enum (tracker, group_ptr, word, word);
     }
-
-  xfree (syscall_list);
-  xfree (group_list);
-  do_cleanups (cleanups);
 }
 
 static void
-- 
2.13.6

  reply	other threads:[~2017-10-18  4:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18  4:06 [RFA 1/3] Remove cleanups from prepare_execute_command Tom Tromey
2017-10-18  4:06 ` Tom Tromey [this message]
2017-10-19 21:00   ` [RFA 3/3] Remove cleanups from break-catch-syscall.c Simon Marchi
2017-10-19 21:57     ` Tom Tromey
2017-10-19 21:57       ` Tom Tromey
2017-10-20 20:26   ` Simon Marchi
2017-10-25  4:42     ` Tom Tromey
2017-10-25 10:38       ` Pedro Alves
2017-10-25 14:50         ` Tom Tromey
2017-12-06 18:58     ` Sergio Durigan Junior
2017-12-06 21:41       ` Simon Marchi
2017-10-18  4:06 ` [RFA 2/3] Remove cleanup from call_function_by_hand_dummy Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171018040645.7212-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).