[aot] Fix a memory leak related to constraint allocation/deallocation. (#4880)
authorvkargov <kargov@gmail.com>
Thu, 18 May 2017 18:08:58 +0000 (11:08 -0700)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 18 May 2017 18:08:58 +0000 (14:08 -0400)
* [jit] Make a copy of the constraint in mini_get_shared_gparam().

* [aot] Free the temporary gshared constraint in decode_class_ref().

mono/mini/aot-runtime.c
mono/mini/mini-generic-sharing.c

index d5ae8dbeece97b2fb080d546eaa4abcf04698354..782106c45e17b519200a104fc6a09695e0e22758 100644 (file)
@@ -505,6 +505,7 @@ decode_klass_ref (MonoAotModule *module, guint8 *buf, guint8 **endbuf, MonoError
                                return NULL;
 
                        t = mini_get_shared_gparam (&par_klass->byval_arg, gshared_constraint);
+                       mono_metadata_free_type (gshared_constraint);
                        klass = mono_class_from_mono_type (t);
                } else {
                        int type = decode_value (p, &p);
index d7475aebd3aff13266a7d01c0419a0fb04b675b2..5ef3b350bf065f713a12e9992a124a9d0c0b5b8f 100644 (file)
@@ -3498,6 +3498,7 @@ mini_get_shared_gparam (MonoType *t, MonoType *constraint)
        copy = (MonoGSharedGenericParam *)mono_image_alloc0 (image, sizeof (MonoGSharedGenericParam));
        memcpy (&copy->param, par, sizeof (MonoGenericParamFull));
        copy->param.info.pklass = NULL;
+       constraint = mono_metadata_type_dup (image, constraint);
        name = get_shared_gparam_name (constraint->type, ((MonoGenericParamFull*)copy)->info.name);
        copy->param.info.name = mono_image_strdup (image, name);
        g_free (name);