This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] Fix infpy_read_memory cleanups handling


[ Not checked-in for archer-tromey-python.  ]

commit 1d39c91be21ffe7295fb63aceb18b11bc2f341c7
Author: Jan Kratochvil <jkratoch@host1.dyn.jankratochvil.net>
Date:   Sun Aug 2 04:28:50 2009 +0200

    Fix infpy_read_memory cleanups handling.
    
    It was crashing gdb.python/python-value.exp during a Fedora merge.
    
    	* python/python-inferior.c (infpy_read_memory): No longer initialize
    	cleanups to NULL, initialize it by null_cleanup later.  Do not
    	reinitialize null_cleanup by xfree make_cleanup.  Call do_cleanups on
    	any error exit path.

diff --git a/gdb/python/python-inferior.c b/gdb/python/python-inferior.c
index fc36550..5e90cc2 100644
--- a/gdb/python/python-inferior.c
+++ b/gdb/python/python-inferior.c
@@ -378,12 +378,14 @@ infpy_read_memory (PyObject *self, PyObject *args)
   void *buffer = NULL;
   membuf_object *membuf_obj;
   PyObject *addr_obj, *length_obj;
-  struct cleanup *cleanups = NULL;
+  struct cleanup *cleanups;
   volatile struct gdb_exception except;
 
   if (! PyArg_ParseTuple (args, "OO", &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)
@@ -394,26 +396,29 @@ infpy_read_memory (PyObject *self, PyObject *args)
 	}
 
       buffer = xmalloc (length);
-      cleanups = make_cleanup (xfree, buffer);
+      make_cleanup (xfree, buffer);
 
       read_memory (addr, buffer, length);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   if (error)
-    return NULL;
-
-  discard_cleanups (cleanups);
+    {
+      do_cleanups (cleanups);
+      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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]