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 crash when deleting types


This fixes a crash when deleting a struct type.

We were failing to properly clear all the fields of a copied type's
'fields' array.

The second part is to avoid referencing freed memory.

The first hunk of this needs to go upstream as well.
I'll send it shortly.

Tom

2008-11-10  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.c (copy_type_recursive): Clear new fields.
	(delete_type_recursive): Move assert after deletion check.

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 55754f2..614f5be 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3000,6 +3000,7 @@ copy_type_recursive (struct objfile *objfile,
 
       nfields = TYPE_NFIELDS (type);
       TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
+      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
       for (i = 0; i < nfields; i++)
 	{
 	  TYPE_FIELD_ARTIFICIAL (new_type, i) = 
@@ -3079,12 +3080,12 @@ delete_type_recursive (struct type *type, htab_t deleted_types)
   if (!type)
     return;
 
-  gdb_assert (!TYPE_OBJFILE (type));
-
   slot = htab_find_slot (deleted_types, type, INSERT);
   if (*slot != NULL)
     return;
 
+  gdb_assert (!TYPE_OBJFILE (type));
+
   *slot = type;
 
   xfree (TYPE_NAME (type));


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