This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] fix crash when deleting types
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Mon, 10 Nov 2008 09:56:05 -0700
- Subject: [python] fix crash when deleting types
- Reply-to: Tom Tromey <tromey at redhat dot com>
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));