Remove more calls to xfree from Python
This changes the Python code to remove some more calls to xfree, in favor of self-managing data structures. Tested on x86-64 Fedora 28. gdb/ChangeLog 2018-12-27 Tom Tromey <tom@tromey.com> * python/python.c (python_interactive_command): Use std::string. (gdbpy_parameter): Likewise. * python/py-utils.c (unicode_to_encoded_string): Update comment. * python/py-symtab.c (salpy_str): Use PyString_FromFormat. * python/py-record-btrace.c (recpy_bt_insn_data): Use byte_vector. * python/py-objfile.c (objfpy_get_build_id): Use unique_xmalloc_ptr. * python/py-inferior.c (infpy_read_memory): Use unique_xmalloc_ptr. * python/py-cmd.c (gdbpy_parse_command_name): Use std::string.
This commit is contained in:
parent
293bf1a719
commit
075c55e0cc
8 changed files with 40 additions and 57 deletions
|
@ -499,7 +499,7 @@ static PyObject *
|
|||
infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
CORE_ADDR addr, length;
|
||||
gdb_byte *buffer = NULL;
|
||||
gdb::unique_xmalloc_ptr<gdb_byte> buffer;
|
||||
PyObject *addr_obj, *length_obj, *result;
|
||||
static const char *keywords[] = { "address", "length", NULL };
|
||||
|
||||
|
@ -513,13 +513,12 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||
|
||||
TRY
|
||||
{
|
||||
buffer = (gdb_byte *) xmalloc (length);
|
||||
buffer.reset ((gdb_byte *) xmalloc (length));
|
||||
|
||||
read_memory (addr, buffer, length);
|
||||
read_memory (addr, buffer.get (), length);
|
||||
}
|
||||
CATCH (except, RETURN_MASK_ALL)
|
||||
{
|
||||
xfree (buffer);
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
}
|
||||
END_CATCH
|
||||
|
@ -527,12 +526,9 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||
gdbpy_ref<membuf_object> membuf_obj (PyObject_New (membuf_object,
|
||||
&membuf_object_type));
|
||||
if (membuf_obj == NULL)
|
||||
{
|
||||
xfree (buffer);
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
membuf_obj->buffer = buffer;
|
||||
membuf_obj->buffer = buffer.release ();
|
||||
membuf_obj->addr = addr;
|
||||
membuf_obj->length = length;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue