From 4d564229605151345eaf05cdbdb3c71cf08bda58 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Fri, 23 May 2014 15:38:35 -0400 Subject: [PATCH] [runtime] Change the semantics of mono_error_set_type_load_name to acquire alloc'd strings. The use case for this function compared to the one that take MonoClass/MonoImage is for lookups and the failed names are usually freshly alloc'd. Fix a leak in class.c usage of mono_error_set_type_load_name. --- mono/utils/mono-error.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mono/utils/mono-error.c b/mono/utils/mono-error.c index ed92085c2aa..a59de349f30 100644 --- a/mono/utils/mono-error.c +++ b/mono/utils/mono-error.c @@ -199,6 +199,10 @@ mono_error_set_type_load_class (MonoError *oerror, MonoClass *klass, const char set_error_message (); } +/* + * Different than other functions, this one here assumes that type_name and assembly_name to have been allocated just for us. + * Which means mono_error_cleanup will free them. + */ void mono_error_set_type_load_name (MonoError *oerror, const char *type_name, const char *assembly_name, const char *msg_format, ...) { @@ -208,6 +212,7 @@ mono_error_set_type_load_name (MonoError *oerror, const char *type_name, const c error->error_code = MONO_ERROR_TYPE_LOAD; mono_error_set_type_name (oerror, type_name); mono_error_set_assembly_name (oerror, assembly_name); + mono_error_dup_strings (oerror, FALSE); set_error_message (); } @@ -273,10 +278,10 @@ mono_error_set_from_loader_error (MonoError *oerror) { MonoLoaderError *loader_error = mono_loader_get_last_error (); MonoErrorInternal *error = (MonoErrorInternal*)oerror; + gboolean dup_strings = TRUE; mono_error_prepare (error); - if (!loader_error) { mono_error_set_generic_error (oerror, "System", "ExecutionEngineException", "Runtime tried to produce a mono-error from an empty loader-error"); return; @@ -311,7 +316,8 @@ mono_error_set_from_loader_error (MonoError *oerror) break; case MONO_EXCEPTION_TYPE_LOAD: - mono_error_set_type_load_name (oerror, loader_error->class_name, loader_error->assembly_name, "Failed for unknown reasons."); + mono_error_set_type_load_name (oerror, g_strdup (loader_error->class_name), g_strdup (loader_error->assembly_name), "Failed for unknown reasons."); + dup_strings = FALSE; break; case MONO_EXCEPTION_FILE_NOT_FOUND: @@ -347,7 +353,7 @@ mono_error_set_from_loader_error (MonoError *oerror) break; } - mono_error_dup_strings (oerror, TRUE); + mono_error_dup_strings (oerror, dup_strings); mono_loader_clear_error (); } -- 2.25.1