Use unique_xmalloc_ptr for read_string
[deliverable/binutils-gdb.git] / gdb / python / py-value.c
index 30a0082da85e4c119b8638cbd4b4323fc1524584..1b880fa191709c10011b154c4b0e4db6af3ff959 100644 (file)
@@ -517,9 +517,8 @@ static PyObject *
 valpy_string (PyObject *self, PyObject *args, PyObject *kw)
 {
   int length = -1;
-  gdb_byte *buffer;
+  gdb::unique_xmalloc_ptr<gdb_byte> buffer;
   struct value *value = ((value_object *) self)->value;
-  PyObject *unicode;
   const char *encoding = NULL;
   const char *errors = NULL;
   const char *user_encoding = NULL;
@@ -542,12 +541,9 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
   END_CATCH
 
   encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
-  unicode = PyUnicode_Decode ((const char *) buffer,
-                             length * TYPE_LENGTH (char_type),
-                             encoding, errors);
-  xfree (buffer);
-
-  return unicode;
+  return PyUnicode_Decode ((const char *) buffer.get (),
+                          length * TYPE_LENGTH (char_type),
+                          encoding, errors);
 }
 
 /* A helper function that implements the various cast operators.  */
This page took 0.023463 seconds and 4 git commands to generate.