2009-07-26 Miguel de Icaza <miguel@novell.com>
[mono.git] / mono / metadata / image.c
index d99b71531531a6508cc6b0e33c15b9ac214f8676..47e85ea3690f288ec47d69d71eecf955f1c90f19 100644 (file)
@@ -130,7 +130,7 @@ mono_images_init (void)
        loaded_images_hash = g_hash_table_new (g_str_hash, g_str_equal);
        loaded_images_refonly_hash = g_hash_table_new (g_str_hash, g_str_equal);
 
-       debug_assembly_unload = getenv ("MONO_DEBUG_ASSEMBLY_UNLOAD") != NULL;
+       debug_assembly_unload = g_getenv ("MONO_DEBUG_ASSEMBLY_UNLOAD") != NULL;
 }
 
 /**
@@ -853,6 +853,21 @@ mono_image_load_cli_data (MonoImage *image)
        return TRUE;
 }
 
+void
+mono_image_load_names (MonoImage *image)
+{
+       /* modules don't have an assembly table row */
+       if (image->tables [MONO_TABLE_ASSEMBLY].rows) {
+               image->assembly_name = mono_metadata_string_heap (image, 
+                       mono_metadata_decode_row_col (&image->tables [MONO_TABLE_ASSEMBLY],
+                                       0, MONO_ASSEMBLY_NAME));
+       }
+
+       image->module_name = mono_metadata_string_heap (image, 
+                       mono_metadata_decode_row_col (&image->tables [MONO_TABLE_MODULE],
+                                       0, MONO_MODULE_NAME));
+}
+
 static MonoImage *
 do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status,
                    gboolean care_about_cli, gboolean care_about_pecoff)
@@ -889,16 +904,10 @@ do_mono_image_load (MonoImage *image, MonoImageOpenStatus *status,
        if (!mono_image_load_cli_data (image))
                goto invalid_image;
 
-       /* modules don't have an assembly table row */
-       if (image->tables [MONO_TABLE_ASSEMBLY].rows) {
-               image->assembly_name = mono_metadata_string_heap (image, 
-                       mono_metadata_decode_row_col (&image->tables [MONO_TABLE_ASSEMBLY],
-                                       0, MONO_ASSEMBLY_NAME));
-       }
+       if (!mono_verifier_verify_table_data (image, NULL))
+               goto invalid_image;
 
-       image->module_name = mono_metadata_string_heap (image, 
-                       mono_metadata_decode_row_col (&image->tables [MONO_TABLE_MODULE],
-                                       0, MONO_MODULE_NAME));
+       mono_image_load_names (image);
 
        load_modules (image);
 
@@ -1308,12 +1317,12 @@ mono_image_fixup_vtable (MonoImage *image)
                if (slot_type & VTFIXUP_TYPE_32BIT)
                        while (slot_count--) {
                                *((guint32*) slot) = (guint32) mono_marshal_get_vtfixup_ftnptr (image, *((guint32*) slot), slot_type);
-                               ((guint32*) slot)++;
+                               slot = ((guint32*) slot) + 1;
                        }
                else if (slot_type & VTFIXUP_TYPE_64BIT)
                        while (slot_count--) {
                                *((guint64*) slot) = (guint64) mono_marshal_get_vtfixup_ftnptr (image, *((guint64*) slot), slot_type);
-                               ((guint64*) slot)++;
+                               slot = ((guint32*) slot) + 1;
                        }
                else
                        g_assert_not_reached();
@@ -1529,7 +1538,6 @@ mono_image_close (MonoImage *image)
        free_hash (image->castclass_cache);
        free_hash (image->proxy_isinst_cache);
        free_hash (image->thunk_invoke_cache);
-       free_hash (image->static_rgctx_invoke_cache);
 
        /* The ownership of signatures is not well defined */
        //g_hash_table_foreach (image->memberref_signatures, free_mr_signatures, NULL);
@@ -1588,7 +1596,10 @@ mono_image_close (MonoImage *image)
                /* Dynamic images are GC_MALLOCed */
                g_free ((char*)image->module_name);
                mono_dynamic_image_free ((MonoDynamicImage*)image);
-               mono_mempool_destroy (image->mempool);
+               if (debug_assembly_unload)
+                       mono_mempool_invalidate (image->mempool);
+               else
+                       mono_mempool_destroy (image->mempool);
        }
 
        mono_profiler_module_event (image, MONO_PROFILE_END_UNLOAD);