diff options
author | Tom Tromey <tromey@adacore.com> | 2021-10-04 08:44:22 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2021-10-04 13:45:38 -0600 |
commit | 3456e70c9d69da8d62a0ea1f8c2e643648afc654 (patch) | |
tree | 7959a8dc460685d2e8e3197478eddb4430d48708 /gdb/gdb-demangle.c | |
parent | e133de4984cef9acb32fd756c607aa2fa1d090fb (diff) | |
download | binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.zip binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.tar.gz binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.tar.bz2 |
Use unique_xmalloc_ptr<char> when demangling
I noticed that some methods in language_defn could use
unique_xmalloc_ptr<char> rather than a plain 'char *'. This patch
implements this change, fixing up the fallout and changing
gdb_demangle to also return this type. In one spot, std::string is
used to simplify some related code, and in another, an auto_obstack is
used to avoid manual management.
Regression tested on x86-64 Fedora 34.
Diffstat (limited to 'gdb/gdb-demangle.c')
-rw-r--r-- | gdb/gdb-demangle.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/gdb/gdb-demangle.c b/gdb/gdb-demangle.c index 24e9200..5382af8 100644 --- a/gdb/gdb-demangle.c +++ b/gdb/gdb-demangle.c @@ -160,7 +160,6 @@ is_cplus_marker (int c) static void demangle_command (const char *args, int from_tty) { - char *demangled; const char *name; const char *arg_start; int processing_args = 1; @@ -202,12 +201,10 @@ demangle_command (const char *args, int from_tty) else lang = current_language; - demangled = language_demangle (lang, name, DMGL_ANSI | DMGL_PARAMS); + gdb::unique_xmalloc_ptr<char> demangled + = language_demangle (lang, name, DMGL_ANSI | DMGL_PARAMS); if (demangled != NULL) - { - printf_filtered ("%s\n", demangled); - xfree (demangled); - } + printf_filtered ("%s\n", demangled.get ()); else error (_("Can't demangle \"%s\""), name); } |