target charset. */
void
-c_get_string (struct value *value, gdb_byte **buffer,
+c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
int *length, struct type **char_type,
const char **charset)
{
/* I is now either a user-defined length, the number of non-null
characters, or FETCHLIMIT. */
*length = i * width;
- *buffer = (gdb_byte *) xmalloc (*length);
- memcpy (*buffer, contents, *length);
+ buffer->reset ((gdb_byte *) xmalloc (*length));
+ memcpy (buffer->get (), contents, *length);
err = 0;
}
else
err = read_string (addr, *length, width, fetchlimit,
byte_order, buffer, length);
if (err != 0)
- {
- xfree (*buffer);
- memory_error (TARGET_XFER_E_IO, addr);
- }
+ memory_error (TARGET_XFER_E_IO, addr);
}
/* If the LENGTH is specified at -1, we want to return the string
if (req_length == -1)
/* If the last character is null, subtract it from LENGTH. */
if (*length > 0
- && extract_unsigned_integer (*buffer + *length - width,
+ && extract_unsigned_integer (buffer->get () + *length - width,
width, byte_order) == 0)
*length -= width;