From d321424cabda97947e66b02242f66881e27ab744 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 12 May 2017 21:24:49 -0400 Subject: [PATCH] [sre] Don't leak coop handles in mono_dynimage_encode_typedef_or_ref_full This function calls mono_class_get_ref_info which allocates a coop handle. However it is called from an icall that wasn't converted to use coop handles yet, so nothing was saving/restoring the handle stack mark, and consequently the handles leak. --- mono/metadata/sre-encode.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mono/metadata/sre-encode.c b/mono/metadata/sre-encode.c index 56a484087fd..89f9a1fdaee 100644 --- a/mono/metadata/sre-encode.c +++ b/mono/metadata/sre-encode.c @@ -771,6 +771,7 @@ guint32 mono_dynimage_encode_typedef_or_ref_full (MonoDynamicImage *assembly, MonoType *type, gboolean try_typespec) { MONO_REQ_GC_UNSAFE_MODE; + HANDLE_FUNCTION_ENTER (); MonoDynamicTable *table; guint32 *values; @@ -779,10 +780,10 @@ mono_dynimage_encode_typedef_or_ref_full (MonoDynamicImage *assembly, MonoType * /* if the type requires a typespec, we must try that first*/ if (try_typespec && (token = create_typespec (assembly, type))) - return token; + goto leave; token = GPOINTER_TO_UINT (g_hash_table_lookup (assembly->typeref, type)); if (token) - return token; + goto leave; klass = mono_class_from_mono_type (type); MonoReflectionTypeBuilderHandle tb = MONO_HANDLE_CAST (MonoReflectionTypeBuilder, mono_class_get_ref_info (klass)); @@ -793,7 +794,7 @@ mono_dynimage_encode_typedef_or_ref_full (MonoDynamicImage *assembly, MonoType * (type->type != MONO_TYPE_MVAR)) { token = MONO_TYPEDEFORREF_TYPEDEF | (MONO_HANDLE_GETVAL (tb, table_idx) << MONO_TYPEDEFORREF_BITS); mono_dynamic_image_register_token (assembly, token, MONO_HANDLE_CAST (MonoObject, tb)); - return token; + goto leave; } if (klass->nested_in) { @@ -816,7 +817,8 @@ mono_dynimage_encode_typedef_or_ref_full (MonoDynamicImage *assembly, MonoType * g_hash_table_insert (assembly->typeref, type, GUINT_TO_POINTER(token)); table->next_idx ++; mono_dynamic_image_register_token (assembly, token, MONO_HANDLE_CAST (MonoObject, tb)); - return token; +leave: + HANDLE_FUNCTION_RETURN_VAL (token); } /* -- 2.25.1