2008-05-30 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Sat, 31 May 2008 00:32:45 +0000 (00:32 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Sat, 31 May 2008 00:32:45 +0000 (00:32 -0000)
* reflection.c (mono_type_get_object): Don't store the suplied
MonoType with type_hash. A caller which pass a type that
was mono_metadata_type_dup'ed cannot free it reliably, as type_hash
might end with a pointer to freed memory.
The solution is to use byval_arg or this_arg from the associated
MonoClass of the supplied type.

svn path=/trunk/mono/; revision=104574

mono/metadata/ChangeLog
mono/metadata/reflection.c

index 753e2d873b870af23ee24307a58edfb9ed5f1aa2..1730146c0f8c768dff36f30318ff0e46367cbdc1 100644 (file)
@@ -1,3 +1,12 @@
+2008-05-30 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * reflection.c (mono_type_get_object): Don't store the suplied
+       MonoType with type_hash. A caller which pass a type that
+       was mono_metadata_type_dup'ed cannot free it reliably, as type_hash
+       might end with a pointer to freed memory.
+       The solution is to use byval_arg or this_arg from the associated
+       MonoClass of the supplied type.
+
 2008-05-29  Zoltan Varga  <vargaz@gmail.com>
 
        * icall.c: Revert the rest of the last change as it breaks the build too.
index f2a528fe0a097084fa0dee9ac720d81be9eb2306..219665e33a516d2bdd50e4596624f327ba744326 100644 (file)
@@ -5721,6 +5721,13 @@ mono_type_get_object (MonoDomain *domain, MonoType *type)
        MonoReflectionType *res;
        MonoClass *klass = mono_class_from_mono_type (type);
 
+       /*we must avoid using @type as it might have come
+        * from a mono_metadata_type_dup and the caller
+        * expects that is can be freed.
+        * Using the right type from 
+        */
+       type = klass->byval_arg.byref == type->byref ? &klass->byval_arg : &klass->this_arg;
+
        mono_domain_lock (domain);
        if (!domain->type_hash)
                domain->type_hash = mono_g_hash_table_new_type ((GHashFunc)mymono_metadata_type_hash,