[reflection] Only duplicate MonoMarshalSpec strings for custom types (mono/mono#17175)
authorRyan Lucia <rylucia@microsoft.com>
Fri, 4 Oct 2019 17:41:56 +0000 (13:41 -0400)
committerAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 4 Oct 2019 17:41:56 +0000 (13:41 -0400)
* [reflection] only duplicate MonoMarshalSpec strings for custom types

* Add test

Commit migrated from https://github.com/mono/mono/commit/05217395db99f0d02a6737ed0491fa65db96632d

src/mono/mono/metadata/loader.c
src/mono/mono/metadata/sre.c

index 095cb36..baf7241 100644 (file)
@@ -2372,13 +2372,16 @@ mono_method_get_marshal_info (MonoMethod *method, MonoMarshalSpec **mspecs)
                                ((MonoDynamicImage*)m_class_get_image (method->klass))->method_aux_hash, method);
                if (method_aux && method_aux->param_marshall) {
                        MonoMarshalSpec **dyn_specs = method_aux->param_marshall;
-                       for (i = 0; i < signature->param_count + 1; ++i)
+                       for (i = 0; i < signature->param_count + 1; ++i) {
                                if (dyn_specs [i]) {
                                        mspecs [i] = g_new0 (MonoMarshalSpec, 1);
                                        memcpy (mspecs [i], dyn_specs [i], sizeof (MonoMarshalSpec));
-                                       mspecs [i]->data.custom_data.custom_name = g_strdup (dyn_specs [i]->data.custom_data.custom_name);
-                                       mspecs [i]->data.custom_data.cookie = g_strdup (dyn_specs [i]->data.custom_data.cookie);
+                                       if (mspecs [i]->native == MONO_NATIVE_CUSTOM) {
+                                               mspecs [i]->data.custom_data.custom_name = g_strdup (dyn_specs [i]->data.custom_data.custom_name);
+                                               mspecs [i]->data.custom_data.cookie = g_strdup (dyn_specs [i]->data.custom_data.cookie);
+                                       }
                                }
+                       }
                }
                return;
        }
index 7e71876..2ecc3e8 100644 (file)
@@ -2168,7 +2168,7 @@ handle_enum:
                        simple_type = mono_class_enum_basetype_internal (type->data.klass)->type;
                        goto handle_enum;
                } else {
-                       g_warning ("generic valutype %s not handled in custom attr value decoding", type->data.klass->name);
+                       g_warning ("generic valuetype %s not handled in custom attr value decoding", type->data.klass->name);
                }
                break;
        case MONO_TYPE_STRING: {