diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index 7274ce756b0250..22da5d35d80c08 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -2306,7 +2306,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ if (klass->parent) { mono_class_setup_fields (klass->parent); if (mono_class_set_type_load_failure_causedby_class (klass, klass->parent, "Cannot initialize parent class")) - return; + goto cleanup; real_size = klass->parent->instance_size; } else { real_size = MONO_ABI_SIZEOF (MonoObject); @@ -2481,24 +2481,24 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ if (extended_layout_kind == EXTENDED_LAYOUT_KIND_CSTRUCT) { if (!m_class_is_valuetype(klass)) { if (mono_class_set_type_load_failure (klass, "CStruct type must be value type.")) - return; + goto cleanup; } mono_class_setup_fields (klass->parent); if (mono_class_set_type_load_failure_causedby_class (klass, klass->parent, "Cannot initialize parent class")) - return; + goto cleanup; real_size = klass->parent->instance_size; if (top == 0) { /* Empty structs are not allowed */ if (mono_class_set_type_load_failure (klass, "CStruct type cannot be empty.")) - return; + goto cleanup; } if (any_field_has_auto_layout) { if (mono_class_set_type_load_failure (klass, "CStruct type cannot have AutoLayout fields.")) - return; + goto cleanup; } klass->blittable = TRUE; @@ -2528,7 +2528,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ if (type_has_references (klass, ftype)) if (mono_class_set_type_load_failure (klass, "CStruct type must not have reference fields.")) - return; + goto cleanup; min_align = MAX (align, min_align); field_offsets [i] = real_size; @@ -2556,7 +2556,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ } else { mono_class_set_type_load_failure (klass, "Unknown extended layout kind '%d'.", extended_layout_kind); - return; + goto cleanup; } } } @@ -2744,7 +2744,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ field_class = mono_class_from_mono_type_internal (field->type); if (mono_class_is_ginst (field_class) && !mono_verifier_class_is_valid_generic_instantiation (field_class)) { mono_class_set_type_load_failure (klass, "Field '%s' is an invalid generic instantiation of type %s", field->name, mono_type_get_full_name (field_class)); - return; + goto cleanup; } } break; @@ -2755,13 +2755,13 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ continue; if ((field->type->attrs & FIELD_ATTRIBUTE_STATIC)) { mono_class_set_type_load_failure (klass, "Static ByRefLike field '%s' is not allowed", field->name); - return; + goto cleanup; } else { /* instance field */ if (allow_isbyreflike_fields) continue; mono_class_set_type_load_failure (klass, "Instance ByRefLike field '%s' not in a ref struct", field->name); - return; + goto cleanup; } } @@ -2780,7 +2780,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ mono_memory_barrier (); klass->fields_inited = 1; mono_loader_unlock (); - +cleanup: g_free (field_offsets); g_free (fields_has_references); } diff --git a/src/mono/mono/metadata/custom-attrs.c b/src/mono/mono/metadata/custom-attrs.c index 8bb0fb414a235d..2eb79da8d5f9e3 100644 --- a/src/mono/mono/metadata/custom-attrs.c +++ b/src/mono/mono/metadata/custom-attrs.c @@ -339,9 +339,9 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha case MONO_TYPE_U1: case MONO_TYPE_I1: case MONO_TYPE_BOOLEAN: { - MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean)); if (!bcheck_blob (p, 0, boundp, error)) return NULL; + MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean)); *bval = *p; *end = p + 1; return bval; @@ -349,9 +349,9 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha case MONO_TYPE_CHAR: case MONO_TYPE_U2: case MONO_TYPE_I2: { - guint16 *val = (guint16 *)g_malloc (sizeof (guint16)); if (!bcheck_blob (p, 1, boundp, error)) return NULL; + guint16 *val = (guint16 *)g_malloc (sizeof (guint16)); *val = read16 (p); *end = p + 2; return val; @@ -363,9 +363,9 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha case MONO_TYPE_R4: case MONO_TYPE_U4: case MONO_TYPE_I4: { - guint32 *val = (guint32 *)g_malloc (sizeof (guint32)); if (!bcheck_blob (p, 3, boundp, error)) return NULL; + guint32 *val = (guint32 *)g_malloc (sizeof (guint32)); *val = read32 (p); *end = p + 4; return val; @@ -376,17 +376,17 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha #endif case MONO_TYPE_U8: case MONO_TYPE_I8: { - guint64 *val = (guint64 *)g_malloc (sizeof (guint64)); if (!bcheck_blob (p, 7, boundp, error)) return NULL; + guint64 *val = (guint64 *)g_malloc (sizeof (guint64)); *val = read64 (p); *end = p + 8; return val; } case MONO_TYPE_R8: { - double *val = (double *)g_malloc (sizeof (double)); if (!bcheck_blob (p, 7, boundp, error)) return NULL; + double *val = (double *)g_malloc (sizeof (double)); readr8 (p, val); *end = p + 8; return val; @@ -667,9 +667,9 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch case MONO_TYPE_U1: case MONO_TYPE_I1: case MONO_TYPE_BOOLEAN: { - MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean)); if (!bcheck_blob (p, 0, boundp, error)) return NULL; + MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean)); *bval = *p; *end = p + 1; result->value.primitive = bval; @@ -678,9 +678,9 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch case MONO_TYPE_CHAR: case MONO_TYPE_U2: case MONO_TYPE_I2: { - guint16 *val = (guint16 *)g_malloc (sizeof (guint16)); if (!bcheck_blob (p, 1, boundp, error)) return NULL; + guint16 *val = (guint16 *)g_malloc (sizeof (guint16)); *val = read16 (p); *end = p + 2; result->value.primitive = val; @@ -693,9 +693,9 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch case MONO_TYPE_R4: case MONO_TYPE_U4: case MONO_TYPE_I4: { - guint32 *val = (guint32 *)g_malloc (sizeof (guint32)); if (!bcheck_blob (p, 3, boundp, error)) return NULL; + guint32 *val = (guint32 *)g_malloc (sizeof (guint32)); *val = read32 (p); *end = p + 4; result->value.primitive = val; @@ -707,18 +707,18 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch #endif case MONO_TYPE_U8: case MONO_TYPE_I8: { - guint64 *val = (guint64 *)g_malloc (sizeof (guint64)); if (!bcheck_blob (p, 7, boundp, error)) return NULL; + guint64 *val = (guint64 *)g_malloc (sizeof (guint64)); *val = read64 (p); *end = p + 8; result->value.primitive = val; return result; } case MONO_TYPE_R8: { - double *val = (double *)g_malloc (sizeof (double)); if (!bcheck_blob (p, 7, boundp, error)) return NULL; + double *val = (double *)g_malloc (sizeof (double)); readr8 (p, val); *end = p + 8; result->value.primitive = val; diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index b68167a77661e9..8e9cdc6120f4bd 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -9298,8 +9298,10 @@ get_concrete_sig (MonoMethodSignature *sig) concrete = FALSE; } copy->has_type_parameters = 0; - if (!concrete) + if (!concrete) { + g_free (copy); return NULL; + } return copy; } diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index 3309eb796b0bc7..d0eb14d72bec0f 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -3107,6 +3107,10 @@ decode_llvm_mono_eh_frame (MonoAotModule *amodule, MonoJitInfo *jinfo, } } g_assert (nindex == ei_len + nested_len); + if (!async) { + g_free (ei); + g_free (type_info); + } } static gpointer