From patchwork Wed Oct 18 04:06:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23659 Received: (qmail 109651 invoked by alias); 18 Oct 2017 04:06:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109470 invoked by uid 89); 18 Oct 2017 04:06:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=holders, tracker X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Oct 2017 04:06:56 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy7.mail.unifiedlayer.com (Postfix) with ESMTP id F3F02215EAC for ; Tue, 17 Oct 2017 22:06:54 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id Ns6r1w00e2f2jeq01s6u8n; Tue, 17 Oct 2017 22:06:54 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=A0EqiRQvp1Vw0PRzcLcA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 184-96-33-178.hlrn.qwest.net ([184.96.33.178]:51166 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e4fd5-001Wr2-Pf; Tue, 17 Oct 2017 22:06:51 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/3] Remove cleanups from break-catch-syscall.c Date: Tue, 17 Oct 2017 22:06:45 -0600 Message-Id: <20171018040645.7212-3-tom@tromey.com> In-Reply-To: <20171018040645.7212-1-tom@tromey.com> References: <20171018040645.7212-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e4fd5-001Wr2-Pf X-Source-Sender: 184-96-33-178.hlrn.qwest.net (bapiya.localdomain) [184.96.33.178]:51166 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes the remaining cleanups from break-catch-syscall.c by storing temporary strings in a vector. ChangeLog 2017-10-17 Tom Tromey * 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 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 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 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