mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-29 15:18:34 +08:00
* python/py-inferior.c (infpy_read_memory): Remove cleanups and
explicitly free 'buffer' on exit paths. Decref 'membuf_object' before returning.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2012-03-28 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
* python/py-inferior.c (infpy_read_memory): Remove cleanups and
|
||||||
|
explicitly free 'buffer' on exit paths. Decref 'membuf_object'
|
||||||
|
before returning.
|
||||||
|
|
||||||
2012-03-28 Tom Tromey <tromey@redhat.com>
|
2012-03-28 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
* .dir-locals.el: New file.
|
* .dir-locals.el: New file.
|
||||||
|
@ -405,8 +405,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
CORE_ADDR addr, length;
|
CORE_ADDR addr, length;
|
||||||
void *buffer = NULL;
|
void *buffer = NULL;
|
||||||
membuf_object *membuf_obj;
|
membuf_object *membuf_obj;
|
||||||
PyObject *addr_obj, *length_obj;
|
PyObject *addr_obj, *length_obj, *result;
|
||||||
struct cleanup *cleanups;
|
|
||||||
volatile struct gdb_exception except;
|
volatile struct gdb_exception except;
|
||||||
static char *keywords[] = { "address", "length", NULL };
|
static char *keywords[] = { "address", "length", NULL };
|
||||||
|
|
||||||
@ -414,8 +413,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
&addr_obj, &length_obj))
|
&addr_obj, &length_obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cleanups = make_cleanup (null_cleanup, NULL);
|
|
||||||
|
|
||||||
TRY_CATCH (except, RETURN_MASK_ALL)
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
if (!get_addr_from_python (addr_obj, &addr)
|
if (!get_addr_from_python (addr_obj, &addr)
|
||||||
@ -426,39 +423,38 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer = xmalloc (length);
|
buffer = xmalloc (length);
|
||||||
make_cleanup (xfree, buffer);
|
|
||||||
|
|
||||||
read_memory (addr, buffer, length);
|
read_memory (addr, buffer, length);
|
||||||
}
|
}
|
||||||
if (except.reason < 0)
|
if (except.reason < 0)
|
||||||
{
|
{
|
||||||
do_cleanups (cleanups);
|
xfree (buffer);
|
||||||
GDB_PY_HANDLE_EXCEPTION (except);
|
GDB_PY_HANDLE_EXCEPTION (except);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
do_cleanups (cleanups);
|
xfree (buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
|
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
|
||||||
if (membuf_obj == NULL)
|
if (membuf_obj == NULL)
|
||||||
{
|
{
|
||||||
|
xfree (buffer);
|
||||||
PyErr_SetString (PyExc_MemoryError,
|
PyErr_SetString (PyExc_MemoryError,
|
||||||
_("Could not allocate memory buffer object."));
|
_("Could not allocate memory buffer object."));
|
||||||
do_cleanups (cleanups);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
discard_cleanups (cleanups);
|
|
||||||
|
|
||||||
membuf_obj->buffer = buffer;
|
membuf_obj->buffer = buffer;
|
||||||
membuf_obj->addr = addr;
|
membuf_obj->addr = addr;
|
||||||
membuf_obj->length = length;
|
membuf_obj->length = length;
|
||||||
|
|
||||||
return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
|
result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
|
||||||
Py_END_OF_BUFFER);
|
Py_END_OF_BUFFER);
|
||||||
|
Py_DECREF (membuf_obj);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implementation of gdb.write_memory (address, buffer [, length]).
|
/* Implementation of gdb.write_memory (address, buffer [, length]).
|
||||||
|
Reference in New Issue
Block a user