[metadata] Rename, null-initialize, and properly free *args variables (mono/mono...
authorMiguel de Icaza <miguel@gnome.org>
Mon, 1 Jul 2019 16:11:02 +0000 (09:11 -0700)
committerAleksey Kliger (λgeek) <alklig@microsoft.com>
Mon, 1 Jul 2019 16:11:02 +0000 (12:11 -0400)
Commit migrated from https://github.com/mono/mono/commit/de18c594f0000812f91ee22c6eb044e2ea3964f0

src/mono/mono/metadata/custom-attrs-internals.h
src/mono/mono/metadata/custom-attrs.c
src/mono/mono/metadata/object-internals.h

index e1d4ef9..21e36df 100644 (file)
@@ -28,7 +28,7 @@ mono_assembly_init_weak_fields (MonoImage *image);
 
 void
 mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len,
-                                                                                                         gpointer **typed_args, gpointer **named_args, int *num_named_args,
+                                                                                                         gpointer **typed_args_out, gpointer **named_args_out, int *num_named_args,
                                                                                                          CattrNamedArg **named_arg_info, MonoError *error);
 
 #endif  /* __MONO_METADATA_REFLECTION_CUSTOM_ATTRS_INTERNALS_H__ */
index 7a4ffb6..c773ca7 100644 (file)
@@ -1013,9 +1013,9 @@ create_custom_attr_into_array (MonoImage *image, MonoMethod *method, const gucha
  * NAMED_ARG_INFO will contain information about the named arguments.
  */
 void
-mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args, MonoArray **named_args, CattrNamedArg **named_arg_info, MonoError *error)
+mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args_out, MonoArray **named_args_out, CattrNamedArg **named_arg_info, MonoError *error)
 {
-       MonoArray *typedargs, *namedargs;
+       MonoArray *typed_args, *named_args;
        MonoClass *attrklass;
        MonoDomain *domain;
        const char *p = (const char*)data;
@@ -1024,10 +1024,13 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
        guint32 i, j, num_named;
        CattrNamedArg *arginfo = NULL;
 
-       *typed_args = NULL;
-       *named_args = NULL;
+       *typed_args_out = NULL;
+       *named_args_out = NULL;
        *named_arg_info = NULL;
 
+       typed_args = NULL;
+       named_args = NULL;
+
        error_init (error);
 
        if (!mono_verifier_verify_cattr_content (image, method, data, len, error))
@@ -1043,9 +1046,9 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
        p += 2;
 
        /* Parse each argument corresponding to the signature's parameters from
-        * the blob and store in typedargs.
+        * the blob and store in typed_args.
         */
-       typedargs = mono_array_new_checked (domain, mono_get_object_class (), mono_method_signature_internal (method)->param_count, error);
+       typed_args = mono_array_new_checked (domain, mono_get_object_class (), mono_method_signature_internal (method)->param_count, error);
        return_if_nok (error);
 
        for (i = 0; i < mono_method_signature_internal (method)->param_count; ++i) {
@@ -1053,7 +1056,7 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
 
                obj = load_cattr_value_boxed (domain, image, mono_method_signature_internal (method)->params [i], p, data_end, &p, error);
                return_if_nok (error);
-               mono_array_setref_internal (typedargs, i, obj);
+               mono_array_setref_internal (typed_args, i, obj);
        }
 
        named = p;
@@ -1062,7 +1065,7 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
        if (!bcheck_blob (named, 1, data_end, error))
                return;
        num_named = read16 (named);
-       namedargs = mono_array_new_checked (domain, mono_get_object_class (), num_named, error);
+       named_args = mono_array_new_checked (domain, mono_get_object_class (), num_named, error);
        return_if_nok (error);
        named += 2;
        attrklass = method->klass;
@@ -1126,7 +1129,7 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
                                g_free (name);
                                return;
                        }
-                       mono_array_setref_internal (namedargs, j, obj);
+                       mono_array_setref_internal (named_args, j, obj);
 
                } else if (named_type == CATTR_TYPE_PROPERTY) {
                        /* Named arg is a property */
@@ -1150,13 +1153,13 @@ mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *meth
                                g_free (name);
                                return;
                        }
-                       mono_array_setref_internal (namedargs, j, obj);
+                       mono_array_setref_internal (named_args, j, obj);
                }
                g_free (name);
        }
 
-       *typed_args = typedargs;
-       *named_args = namedargs;
+       *typed_args_out = typed_args;
+       *named_args_out = named_args;
        return;
 fail:
        mono_error_set_generic_error (error, "System.Reflection", "CustomAttributeFormatException", "Binary format of the specified custom attribute was invalid.");
@@ -1173,10 +1176,10 @@ fail:
  */
 void
 mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len,
-                                                                                                         gpointer **typed_args, gpointer **named_args, int *num_named_args,
+                                                                                                         gpointer **typed_args_out, gpointer **named_args_out, int *num_named_args,
                                                                                                          CattrNamedArg **named_arg_info, MonoError *error)
 {
-       gpointer *typedargs, *namedargs;
+       gpointer *typed_args, *named_args;
        MonoClass *attrklass;
        const char *p = (const char*)data;
        const char *data_end = p + len;
@@ -1185,10 +1188,13 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
        CattrNamedArg *arginfo = NULL;
        MonoMethodSignature *sig = mono_method_signature_internal (method);
 
-       *typed_args = NULL;
-       *named_args = NULL;
+       *typed_args_out = NULL;
+       *named_args_out = NULL;
        *named_arg_info = NULL;
 
+       typed_args = NULL;
+       named_args = NULL;
+
        error_init (error);
 
        if (!mono_verifier_verify_cattr_content (image, method, data, len, error))
@@ -1202,10 +1208,10 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
        /* skip prolog */
        p += 2;
 
-       typedargs = g_new0 (gpointer, sig->param_count);
+       typed_args = g_new0 (gpointer, sig->param_count);
 
        for (i = 0; i < sig->param_count; ++i) {
-               typedargs [i] = load_cattr_value (image, sig->params [i], NULL, p, data_end, &p, error);
+               typed_args [i] = load_cattr_value (image, sig->params [i], NULL, p, data_end, &p, error);
                return_if_nok (error);
        }
 
@@ -1215,7 +1221,7 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
        if (!bcheck_blob (named, 1, data_end, error))
                goto fail;
        num_named = read16 (named);
-       namedargs = g_new0 (gpointer, num_named);
+       named_args = g_new0 (gpointer, num_named);
        return_if_nok (error);
        named += 2;
        attrklass = method->klass;
@@ -1274,10 +1280,10 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
                        arginfo [j].type = field->type;
                        arginfo [j].field = field;
 
-                   namedargs [j] = load_cattr_value (image, field->type, NULL, named, data_end, &named, error);
+                   named_args [j] = load_cattr_value (image, field->type, NULL, named, data_end, &named, error);
                        if (!is_ok (error)) {
                                g_free (name);
-                               return;
+                               goto fail;
                        }
                } else if (named_type == CATTR_TYPE_PROPERTY) {
                        /* Named arg is a property */
@@ -1295,29 +1301,31 @@ mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMeth
                        arginfo [j].type = prop_type;
                        arginfo [j].prop = prop;
 
-                       namedargs [j] = load_cattr_value (image, prop_type, NULL, named, data_end, &named, error);
+                       named_args [j] = load_cattr_value (image, prop_type, NULL, named, data_end, &named, error);
                        if (!is_ok (error)) {
                                g_free (name);
-                               return;
+                               goto fail;
                        }
                }
                g_free (name);
        }
 
-       *typed_args = typedargs;
-       *named_args = namedargs;
+       *typed_args_out = typed_args;
+       *named_args_out = named_args;
        return;
 fail:
        mono_error_set_generic_error (error, "System.Reflection", "CustomAttributeFormatException", "Binary format of the specified custom attribute was invalid.");
+       g_free (typed_args);
+       g_free (named_args);
        g_free (arginfo);
        *named_arg_info = NULL;
 }
 
 static gboolean
-reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, MonoReflectionAssembly *assembly, gpointer data, guint32 len, MonoArray **ctor_args, MonoArray **named_args, MonoError *error)
+reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, MonoReflectionAssembly *assembly, gpointer data, guint32 len, MonoArray **ctor_args, MonoArray **named_args_out, MonoError *error)
 {
        MonoDomain *domain;
-       MonoArray *typedargs, *namedargs;
+       MonoArray *typed_args, *named_args;
        MonoImage *image;
        MonoMethod *method;
        CattrNamedArg *arginfo = NULL;
@@ -1326,7 +1334,10 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
        error_init (error);
 
        *ctor_args = NULL;
-       *named_args = NULL;
+       *named_args_out = NULL;
+
+       typed_args = NULL;
+       named_args = NULL;
 
        if (len == 0)
                return TRUE;
@@ -1340,14 +1351,14 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
                goto leave;
        }
 
-       mono_reflection_create_custom_attr_data_args (image, method, (const guchar *)data, len, &typedargs, &namedargs, &arginfo, error);
+       mono_reflection_create_custom_attr_data_args (image, method, (const guchar *)data, len, &typed_args, &named_args, &arginfo, error);
        goto_if_nok (error, leave);
 
-       if (!typedargs || !namedargs)
+       if (!typed_args || !named_args)
                goto leave;
 
        for (i = 0; i < mono_method_signature_internal (method)->param_count; ++i) {
-               MonoObject *obj = mono_array_get_internal (typedargs, MonoObject*, i);
+               MonoObject *obj = mono_array_get_internal (typed_args, MonoObject*, i);
                MonoObject *typedarg;
                MonoType *t;
 
@@ -1357,11 +1368,11 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
                typedarg = create_cattr_typed_arg (t, obj, error);
 
                goto_if_nok (error, leave);
-               mono_array_setref_internal (typedargs, i, typedarg);
+               mono_array_setref_internal (typed_args, i, typedarg);
        }
 
-       for (i = 0; i < mono_array_length_internal (namedargs); ++i) {
-               MonoObject *obj = mono_array_get_internal (namedargs, MonoObject*, i);
+       for (i = 0; i < mono_array_length_internal (named_args); ++i) {
+               MonoObject *obj = mono_array_get_internal (named_args, MonoObject*, i);
                MonoObject *namedarg, *minfo;
 
                if (arginfo [i].prop) {
@@ -1382,11 +1393,11 @@ reflection_resolve_custom_attribute_data (MonoReflectionMethod *ref_method, Mono
 #endif
                goto_if_nok (error, leave);
 
-               mono_array_setref_internal (namedargs, i, namedarg);
+               mono_array_setref_internal (named_args, i, namedarg);
        }
 
-       *ctor_args = typedargs;
-       *named_args = namedargs;
+       *ctor_args = typed_args;
+       *named_args_out = named_args;
 
 leave:
        g_free (arginfo);
index 6b92a03..5e29709 100644 (file)
@@ -1673,7 +1673,7 @@ ves_icall_SymbolType_create_unmanaged_type (MonoReflectionType *type);
 
 void        mono_reflection_register_with_runtime (MonoReflectionType *type);
 
-void        mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args, MonoArray **named_args, CattrNamedArg **named_arg_info, MonoError *error);
+void        mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArray **typed_args_out, MonoArray **named_args_out, CattrNamedArg **named_arg_info, MonoError *error);
 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
 
 MonoArrayHandle mono_param_get_objects_internal  (MonoDomain *domain, MonoMethod *method, MonoClass *refclass, MonoError *error);