Use unique_xmalloc_ptr in Python code
[deliverable/binutils-gdb.git] / gdb / python / py-value.c
index 926a09c8512df850168af886c2054cebbf532734..b959f2e10dd17a5042cdee3b63ab3677b56bfc17 100644 (file)
@@ -667,7 +667,7 @@ valpy_getitem (PyObject *self, PyObject *key)
 {
   struct gdb_exception except = exception_none;
   value_object *self_value = (value_object *) self;
-  char *field = NULL;
+  gdb::unique_xmalloc_ptr<char> field;
   struct type *base_class_type = NULL, *field_type = NULL;
   long bitpos = -1;
   PyObject *result = NULL;
@@ -754,7 +754,7 @@ valpy_getitem (PyObject *self, PyObject *key)
       struct value *res_val = NULL;
 
       if (field)
-       res_val = value_struct_elt (&tmp, NULL, field, NULL,
+       res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
                                    "struct/class/union");
       else if (bitpos >= 0)
        res_val = value_struct_elt_bitpos (&tmp, bitpos, field_type,
@@ -804,7 +804,6 @@ valpy_getitem (PyObject *self, PyObject *key)
     }
   END_CATCH
 
-  xfree (field);
   GDB_PY_HANDLE_EXCEPTION (except);
 
   return result;
@@ -1663,17 +1662,11 @@ convert_value_from_python (PyObject *obj)
        }
       else if (gdbpy_is_string (obj))
        {
-         char *s;
-
-         s = python_string_to_target_string (obj);
+         gdb::unique_xmalloc_ptr<char> s
+           = python_string_to_target_string (obj);
          if (s != NULL)
-           {
-             struct cleanup *old;
-
-             old = make_cleanup (xfree, s);
-             value = value_cstring (s, strlen (s), builtin_type_pychar);
-             do_cleanups (old);
-           }
+           value = value_cstring (s.get (), strlen (s.get ()),
+                                  builtin_type_pychar);
        }
       else if (PyObject_TypeCheck (obj, &value_object_type))
        value = value_copy (((value_object *) obj)->value);
This page took 0.02519 seconds and 4 git commands to generate.