From 573b986724f7ceea5bdda68d54238414707c81de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:23:33 +0000 Subject: [PATCH 1/4] Initial plan From 5b575b5779dfa28df39eb89bf11fbc743c0f8d37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:28:56 +0000 Subject: [PATCH 2/4] Fix memory leaks from mono_type_full_name in marshal-shared.c error paths Co-authored-by: lewing <24063+lewing@users.noreply.github.com> --- src/mono/mono/metadata/marshal-shared.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/marshal-shared.c b/src/mono/mono/metadata/marshal-shared.c index bd786c3944492a..b91f782284fec8 100644 --- a/src/mono/mono/metadata/marshal-shared.c +++ b/src/mono/mono/metadata/marshal-shared.c @@ -774,8 +774,10 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla if (klass != mono_class_try_get_safehandle_class ()) { if (mono_class_is_auto_layout (klass)) { + char *type_name = mono_type_full_name (m_class_get_byval_arg (klass)); char *msg = g_strdup_printf ("Type %s which is passed to unmanaged code must have a StructLayout attribute.", - mono_type_full_name (m_class_get_byval_arg (klass))); + type_name); + g_free (type_name); mono_marshal_shared_mb_emit_exception_marshal_directive (mb, msg); return; } @@ -810,10 +812,13 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla if (mono_class_is_explicit_layout (klass) && (usize == 0)) { if (MONO_TYPE_IS_REFERENCE (info->fields [i].field->type) || - ((!last_field && MONO_TYPE_IS_REFERENCE (info->fields [i + 1].field->type)))) + ((!last_field && MONO_TYPE_IS_REFERENCE (info->fields [i + 1].field->type)))) { + char *type_name = mono_type_full_name (m_class_get_byval_arg (klass)); g_error ("Type %s which has an [ExplicitLayout] attribute cannot have a " "reference field at the same offset as another field.", - mono_type_full_name (m_class_get_byval_arg (klass))); + type_name); + g_free (type_name); + } } } @@ -862,8 +867,10 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla break; case MONO_TYPE_GENERICINST: if (!mono_type_generic_inst_is_valuetype (ftype)) { + char *type_name = mono_type_full_name (ftype); char *msg = g_strdup_printf ("Generic type %s cannot be marshaled as field in a struct.", - mono_type_full_name (ftype)); + type_name); + g_free (type_name); mono_marshal_shared_mb_emit_exception_marshal_directive (mb, msg); break; } @@ -908,9 +915,13 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla case MONO_TYPE_CLASS: case MONO_TYPE_SZARRAY: case MONO_TYPE_ARRAY: { + char *klass_name = mono_type_full_name (m_class_get_byval_arg (klass)); + char *field_type_name = mono_type_full_name (ftype); char *msg = g_strdup_printf ("Type %s with field type %s cannot be marshaled as an unmanaged struct field.", - mono_type_full_name (m_class_get_byval_arg (klass)), - mono_type_full_name (ftype)); + klass_name, + field_type_name); + g_free (klass_name); + g_free (field_type_name); mono_marshal_shared_mb_emit_exception_marshal_directive (mb, msg); break; } From 3ef96fb029b3108c696cb3940c252df8368b02a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 14:36:27 +0000 Subject: [PATCH 3/4] Remove dead g_free after g_error (which never returns) in marshal-shared.c Co-authored-by: lewing <24063+lewing@users.noreply.github.com> --- src/mono/mono/metadata/marshal-shared.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/mono/metadata/marshal-shared.c b/src/mono/mono/metadata/marshal-shared.c index b91f782284fec8..512e6e57db5dfc 100644 --- a/src/mono/mono/metadata/marshal-shared.c +++ b/src/mono/mono/metadata/marshal-shared.c @@ -817,7 +817,6 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla g_error ("Type %s which has an [ExplicitLayout] attribute cannot have a " "reference field at the same offset as another field.", type_name); - g_free (type_name); } } } From 56129333b1d05b60c0d92189b9abafc3eb508dd7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 19:33:22 +0000 Subject: [PATCH 4/4] Fix unused-variable build error in WASM/WASI: revert g_error site to inline form Co-authored-by: lewing <24063+lewing@users.noreply.github.com> --- src/mono/mono/metadata/marshal-shared.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/metadata/marshal-shared.c b/src/mono/mono/metadata/marshal-shared.c index 512e6e57db5dfc..1fd597162a62ca 100644 --- a/src/mono/mono/metadata/marshal-shared.c +++ b/src/mono/mono/metadata/marshal-shared.c @@ -812,12 +812,10 @@ mono_marshal_shared_emit_struct_conv_full (MonoMethodBuilder *mb, MonoClass *kla if (mono_class_is_explicit_layout (klass) && (usize == 0)) { if (MONO_TYPE_IS_REFERENCE (info->fields [i].field->type) || - ((!last_field && MONO_TYPE_IS_REFERENCE (info->fields [i + 1].field->type)))) { - char *type_name = mono_type_full_name (m_class_get_byval_arg (klass)); + ((!last_field && MONO_TYPE_IS_REFERENCE (info->fields [i + 1].field->type)))) g_error ("Type %s which has an [ExplicitLayout] attribute cannot have a " "reference field at the same offset as another field.", - type_name); - } + mono_type_full_name (m_class_get_byval_arg (klass))); } }