Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -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);
}
Expand Down
46 changes: 34 additions & 12 deletions src/mono/mono/metadata/custom-attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha
case MONO_TYPE_I1:
case MONO_TYPE_BOOLEAN: {
MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean));
if (!bcheck_blob (p, 0, boundp, error))
if (!bcheck_blob (p, 0, boundp, error)) {
g_free (bval);
return NULL;
}
*bval = *p;
*end = p + 1;
return bval;
Expand All @@ -350,8 +352,10 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha
case MONO_TYPE_U2:
case MONO_TYPE_I2: {
guint16 *val = (guint16 *)g_malloc (sizeof (guint16));
if (!bcheck_blob (p, 1, boundp, error))
if (!bcheck_blob (p, 1, boundp, error)) {
g_free (val);
return NULL;
}
*val = read16 (p);
*end = p + 2;
return val;
Expand All @@ -364,8 +368,10 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha
case MONO_TYPE_U4:
case MONO_TYPE_I4: {
guint32 *val = (guint32 *)g_malloc (sizeof (guint32));
if (!bcheck_blob (p, 3, boundp, error))
if (!bcheck_blob (p, 3, boundp, error)) {
g_free (val);
return NULL;
}
*val = read32 (p);
*end = p + 4;
return val;
Expand All @@ -377,16 +383,20 @@ load_cattr_value (MonoImage *image, MonoType *t, MonoObject **out_obj, const cha
case MONO_TYPE_U8:
case MONO_TYPE_I8: {
guint64 *val = (guint64 *)g_malloc (sizeof (guint64));
if (!bcheck_blob (p, 7, boundp, error))
if (!bcheck_blob (p, 7, boundp, error)) {
g_free (val);
return NULL;
}
*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))
if (!bcheck_blob (p, 7, boundp, error)){
g_free (val);
return NULL;
}
readr8 (p, val);
*end = p + 8;
return val;
Expand Down Expand Up @@ -668,8 +678,10 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch
case MONO_TYPE_I1:
case MONO_TYPE_BOOLEAN: {
MonoBoolean *bval = (MonoBoolean *)g_malloc (sizeof (MonoBoolean));
if (!bcheck_blob (p, 0, boundp, error))
if (!bcheck_blob (p, 0, boundp, error)) {
g_free (bval);
return NULL;
}
*bval = *p;
*end = p + 1;
result->value.primitive = bval;
Expand All @@ -679,8 +691,10 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch
case MONO_TYPE_U2:
case MONO_TYPE_I2: {
guint16 *val = (guint16 *)g_malloc (sizeof (guint16));
if (!bcheck_blob (p, 1, boundp, error))
if (!bcheck_blob (p, 1, boundp, error)) {
g_free (val);
return NULL;
}
*val = read16 (p);
*end = p + 2;
result->value.primitive = val;
Expand All @@ -694,8 +708,10 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch
case MONO_TYPE_U4:
case MONO_TYPE_I4: {
guint32 *val = (guint32 *)g_malloc (sizeof (guint32));
if (!bcheck_blob (p, 3, boundp, error))
if (!bcheck_blob (p, 3, boundp, error)) {
g_free (val);
return NULL;
}
*val = read32 (p);
*end = p + 4;
result->value.primitive = val;
Expand All @@ -708,17 +724,21 @@ load_cattr_value_noalloc (MonoImage *image, MonoType *t, const char *p, const ch
case MONO_TYPE_U8:
case MONO_TYPE_I8: {
guint64 *val = (guint64 *)g_malloc (sizeof (guint64));
if (!bcheck_blob (p, 7, boundp, error))
if (!bcheck_blob (p, 7, boundp, error)) {
g_free (val);
return NULL;
}
*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))
if (!bcheck_blob (p, 7, boundp, error)) {
g_free (val);
return NULL;
}
readr8 (p, val);
*end = p + 8;
result->value.primitive = val;
Expand Down Expand Up @@ -1553,7 +1573,8 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
decoded_args->typed_args = g_malloc0 (sig->param_count * sizeof (MonoCustomAttrValue*));
for (i = 0; i < sig->param_count; ++i) {
decoded_args->typed_args [i] = load_cattr_value_noalloc (image, sig->params [i], p, data_end, &p, error);
return_val_if_nok (error, NULL);
if (!is_ok (error))
goto fail;
}

named = p;
Expand All @@ -1566,7 +1587,8 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
decoded_args->named_args_num = num_named;
decoded_args->named_args = g_malloc0 (num_named * sizeof (MonoCustomAttrValue*));

return_val_if_nok (error, NULL);
if (!is_ok (error))
goto fail;
named += 2;
attrklass = method->klass;

Expand Down
4 changes: 3 additions & 1 deletion src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,11 @@ 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);
g_free (unw_info);
}
}

static gpointer
Expand Down
Loading