From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/4] Remove cleanup from add_path
Date: Mon, 03 Sep 2018 19:02:00 -0000 [thread overview]
Message-ID: <20180903190250.11599-2-tom@tromey.com> (raw)
In-Reply-To: <20180903190250.11599-1-tom@tromey.com>
This removes a cleanup from add_path, replacing it with a use of
gdb::unique_xmalloc_ptr. Note that this declaration had to be hoisted
somewhat, to avoid inteference from the "goto"s in this function.
gdb/ChangeLog
2018-09-03 Tom Tromey <tom@tromey.com>
* source.c (add_path): Use gdb::unique_xmalloc_ptr.
---
gdb/ChangeLog | 4 ++++
gdb/source.c | 16 +++++++---------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/gdb/source.c b/gdb/source.c
index cc5c46d0a7b..ec0ea3b81e3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -479,13 +479,12 @@ add_path (const char *dirname, char **which_path, int parse_separators)
else
dir_vec.emplace_back (xstrdup (dirname));
- struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
-
for (const gdb::unique_xmalloc_ptr<char> &name_up : dir_vec)
{
char *name = name_up.get ();
char *p;
struct stat st;
+ gdb::unique_xmalloc_ptr<char> new_name_holder;
/* Spaces and tabs will have been removed by buildargv().
NAME is the start of the directory.
@@ -531,16 +530,17 @@ add_path (const char *dirname, char **which_path, int parse_separators)
}
if (name[0] == '~')
- name = tilde_expand (name);
+ new_name_holder.reset (tilde_expand (name));
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */
- name = concat (name, ".", (char *)NULL);
+ new_name_holder.reset (concat (name, ".", (char *) NULL));
#endif
else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$')
- name = concat (current_directory, SLASH_STRING, name, (char *)NULL);
+ new_name_holder.reset (concat (current_directory, SLASH_STRING, name,
+ (char *) NULL));
else
- name = savestring (name, p - name);
- make_cleanup (xfree, name);
+ new_name_holder.reset (savestring (name, p - name));
+ name = new_name_holder.get ();
/* Unless it's a variable, check existence. */
if (name[0] != '$')
@@ -630,8 +630,6 @@ add_path (const char *dirname, char **which_path, int parse_separators)
skip_dup:
;
}
-
- do_cleanups (back_to);
}
--
2.13.6
next prev parent reply other threads:[~2018-09-03 19:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-03 19:03 [PATCH 0/4] Some cleanup removal Tom Tromey
2018-09-03 19:02 ` Tom Tromey [this message]
2018-09-03 19:03 ` [PATCH 4/4] Remove cleanup from try_open_exec_file Tom Tromey
2018-09-03 19:03 ` [PATCH 2/4] Remove cleanup from procfs.c Tom Tromey
2018-09-04 10:50 ` Rainer Orth
2018-09-04 16:56 ` Tom Tromey
2018-09-03 19:03 ` [PATCH 3/4] Return std::string from gdb_bfd_errmsg Tom Tromey
2018-09-04 9:37 ` [PATCH 0/4] Some cleanup removal Rainer Orth
2018-09-04 16:58 ` Tom Tromey
2018-09-04 18:30 ` Rainer Orth
2018-09-13 22:41 ` 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=20180903190250.11599-2-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