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][commit] Fix memory allocation bug in gdbpy_read_memory.


Hi,

Phil mentioned that python-membuf.exp was failing on x86_64. Turned out
to be a very silly bug in my code. I'm surprised that it worked at all
in x86, ppc32 and ppc64.
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


commit a3f53d04c2005ca3ebe4d1f9d8a35d3b0746e01c
Author: Thiago Jung Bauermann <bauerman@br.ibm.com>
Date:   Wed Apr 1 15:26:15 2009 -0300

    Fix memory allocation bug in gdbpy_read_memory.
    
    	* python/python-membuf.c (gdbpy_read_memory): Allocate buffer
    	after its length has been determined.

diff --git a/gdb/python/python-membuf.c b/gdb/python/python-membuf.c
index d422d1c..d180a18 100644
--- a/gdb/python/python-membuf.c
+++ b/gdb/python/python-membuf.c
@@ -45,15 +45,12 @@ gdbpy_read_memory (PyObject *self, PyObject *args)
   void *buffer;
   membuf_object *membuf_obj;
   PyObject *addr_obj, *length_obj;
-  struct cleanup *cleanups;
+  struct cleanup *cleanups = NULL;
   volatile struct gdb_exception except;
 
   if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
     return NULL;
 
-  buffer = xmalloc (length);
-  cleanups = make_cleanup (xfree, buffer);
-
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
       if (!get_addr_from_python (addr_obj, &addr)
@@ -63,15 +60,15 @@ gdbpy_read_memory (PyObject *self, PyObject *args)
 	  break;
 	}
 
+      buffer = xmalloc (length);
+      cleanups = make_cleanup (xfree, buffer);
+
       read_memory (addr, buffer, length);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   if (error)
-    {
-      do_cleanups (cleanups);
-      return NULL;
-    }
+    return NULL;
 
   discard_cleanups (cleanups);
 



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