From cc0265cdda9dc7e8665e8bfcf5b4477489daf27c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 28 Mar 2012 17:38:08 +0000 Subject: [PATCH] * python/py-inferior.c (infpy_read_memory): Remove cleanups and explicitly free 'buffer' on exit paths. Decref 'membuf_object' before returning. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-inferior.c | 20 ++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3d8489c58dd..2e6c8c9e936 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2012-03-28 Tom Tromey + + * 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 * .dir-locals.el: New file. diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 339a2210350..06d327272c0 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -405,8 +405,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) CORE_ADDR addr, length; void *buffer = NULL; membuf_object *membuf_obj; - PyObject *addr_obj, *length_obj; - struct cleanup *cleanups; + PyObject *addr_obj, *length_obj, *result; volatile struct gdb_exception except; static char *keywords[] = { "address", "length", NULL }; @@ -414,8 +413,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) &addr_obj, &length_obj)) return NULL; - cleanups = make_cleanup (null_cleanup, NULL); - TRY_CATCH (except, RETURN_MASK_ALL) { if (!get_addr_from_python (addr_obj, &addr) @@ -426,39 +423,38 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) } buffer = xmalloc (length); - make_cleanup (xfree, buffer); read_memory (addr, buffer, length); } if (except.reason < 0) { - do_cleanups (cleanups); + xfree (buffer); GDB_PY_HANDLE_EXCEPTION (except); } if (error) { - do_cleanups (cleanups); + xfree (buffer); return NULL; } membuf_obj = PyObject_New (membuf_object, &membuf_object_type); if (membuf_obj == NULL) { + xfree (buffer); PyErr_SetString (PyExc_MemoryError, _("Could not allocate memory buffer object.")); - do_cleanups (cleanups); return NULL; } - discard_cleanups (cleanups); - membuf_obj->buffer = buffer; membuf_obj->addr = addr; membuf_obj->length = length; - return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0, - Py_END_OF_BUFFER); + result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0, + Py_END_OF_BUFFER); + Py_DECREF (membuf_obj); + return result; } /* Implementation of gdb.write_memory (address, buffer [, length]). -- 2.30.2