aboutsummaryrefslogtreecommitdiff
path: root/gdb/charset.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2021-11-08 14:58:46 +0000
committerAndrew Burgess <aburgess@redhat.com>2021-11-16 17:45:45 +0000
commit8579fd136a614985bd27f20539c7bb7c5a51287d (patch)
treefb84850409a44e13e832cbadc9025d40c1d33d9f /gdb/charset.c
parent2bb7589ddf61e163f2e414e7033fad56ea17e784 (diff)
downloadgdb-8579fd136a614985bd27f20539c7bb7c5a51287d.zip
gdb-8579fd136a614985bd27f20539c7bb7c5a51287d.tar.gz
gdb-8579fd136a614985bd27f20539c7bb7c5a51287d.tar.bz2
gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr
The motivation is to reduce the number of places where unmanaged pointers are returned from allocation type routines. All of the callers are updated. There should be no user visible changes after this commit.
Diffstat (limited to 'gdb/charset.c')
-rw-r--r--gdb/charset.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/gdb/charset.c b/gdb/charset.c
index 9fb1a1f..d1aebaa 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -960,35 +960,31 @@ intermediate_encoding (void)
{
iconv_t desc;
static const char *stored_result = NULL;
- char *result;
+ gdb::unique_xmalloc_ptr<char> result;
if (stored_result)
return stored_result;
result = xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t) * 8),
ENDIAN_SUFFIX);
/* Check that the name is supported by iconv_open. */
- desc = iconv_open (result, host_charset ());
+ desc = iconv_open (result.get (), host_charset ());
if (desc != (iconv_t) -1)
{
iconv_close (desc);
- stored_result = result;
- return result;
+ stored_result = result.release ();
+ return stored_result;
}
- /* Not valid, free the allocated memory. */
- xfree (result);
/* Second try, with UCS-2 type. */
result = xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t),
ENDIAN_SUFFIX);
/* Check that the name is supported by iconv_open. */
- desc = iconv_open (result, host_charset ());
+ desc = iconv_open (result.get (), host_charset ());
if (desc != (iconv_t) -1)
{
iconv_close (desc);
- stored_result = result;
- return result;
+ stored_result = result.release ();
+ return stored_result;
}
- /* Not valid, free the allocated memory. */
- xfree (result);
/* No valid charset found, generate error here. */
error (_("Unable to find a valid charset for string conversions"));
}