From patchwork Tue Aug 29 19:25:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22406 Received: (qmail 84352 invoked by alias); 29 Aug 2017 19:25:40 -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 83944 invoked by uid 89); 29 Aug 2017 19:25:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*tom, tromey X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 19:25:33 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 42016140754 for ; Tue, 29 Aug 2017 13:25:32 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 37RV1w0182f2jeq017RYBR; Tue, 29 Aug 2017 13:25:32 -0600 X-Authority-Analysis: v=2.2 cv=IspuSP3g c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=GPqbNtaPD_3F5veGivIA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:36914 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dmm8f-004DCm-2M; Tue, 29 Aug 2017 13:25:29 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 05/10] Use unique_xmalloc_ptr in cd_command Date: Tue, 29 Aug 2017 13:25:19 -0600 Message-Id: <20170829192524.29971-6-tom@tromey.com> In-Reply-To: <20170829192524.29971-1-tom@tromey.com> References: <20170829192524.29971-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dmm8f-004DCm-2M X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:36914 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes Change cd_command to use unique_xmalloc_ptr, removing a cleanup. ChangeLog 2017-08-29 Tom Tromey * cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr. --- gdb/ChangeLog | 4 ++++ gdb/cli/cli-cmds.c | 20 +++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b13ce63..1d9ff74 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-08-29 Tom Tromey + * cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr. + +2017-08-29 Tom Tromey + * mi/mi-interp.c (mi_cmd_interpreter_exec): Use std::string. 2017-08-29 Tom Tromey diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index d4dc539..8221747 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -398,14 +398,14 @@ cd_command (char *dir, int from_tty) /* Found something other than leading repetitions of "/..". */ int found_real_path; char *p; - struct cleanup *cleanup; /* If the new directory is absolute, repeat is a no-op; if relative, repeat might be useful but is more likely to be a mistake. */ dont_repeat (); - dir = tilde_expand (dir != NULL ? dir : "~"); - cleanup = make_cleanup (xfree, dir); + gdb::unique_xmalloc_ptr dir_holder + (tilde_expand (dir != NULL ? dir : "~")); + dir = dir_holder.get (); if (chdir (dir) < 0) perror_with_name (dir); @@ -430,17 +430,17 @@ cd_command (char *dir, int from_tty) len--; } - dir = savestring (dir, len); - if (IS_ABSOLUTE_PATH (dir)) - current_directory = dir; + dir_holder.reset (savestring (dir, len)); + if (IS_ABSOLUTE_PATH (dir_holder.get ())) + current_directory = dir_holder.release (); else { if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])) - current_directory = concat (current_directory, dir, (char *)NULL); + current_directory = concat (current_directory, dir_holder.get (), + (char *) NULL); else current_directory = concat (current_directory, SLASH_STRING, - dir, (char *)NULL); - xfree (dir); + dir_holder.get (), (char *) NULL); } /* Now simplify any occurrences of `.' and `..' in the pathname. */ @@ -489,8 +489,6 @@ cd_command (char *dir, int from_tty) if (from_tty) pwd_command ((char *) 0, 1); - - do_cleanups (cleanup); } /* Show the current value of the 'script-extension' option. */