i386: Use g_autofree in a few places
PATCH 1/1 i386: Use g_autofree in a few places
Get rid of 12 explicit g_free() calls.
Signed-off-by Eduardo Habkost <[email protected]>
--- target/i386/cpu.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-)
target/i386/cpu.c +13 -28
@@ -1671,11 +1671,8 @@ static char *x86_cpu_type_name(const char *model_name)static ObjectClass *x86_cpu_class_by_name (const char *cpu_model) { -ObjectClass *oc; -char *typename =x86_cpu_type_name (cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -return oc; + g_autofree char *typename = x86_cpu_type_name(cpu_model); +return object_class_by_name (typename); }static char *x86_cpu_class_get_model_name (X86CPUClass *cc)
@@ -3407,7 +3404,6 @@ static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask,CPUX86State *env = &cpu->env;FeatureWordInfo *f = &feature_word_info[w];int i; -char *feat_word_str;if (!cpu->force_features) { env->features[w] &= ~mask;
@@ -3420,13 +3416,12 @@ static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask,for (i =0 ; i <64 ; ++i) {if ((1ULL << i) & mask) { - feat_word_str =feature_word_description (f, i); + g_autofree char *feat_word_str = feature_word_description(f, i);warn_report ("%s: %s%s%s [bit %d]" , verbose_prefix, feat_word_str, f->feat_names[i] ?"." :"" , f->feat_names[i] ? f->feat_names[i] :"" , i); -g_free (feat_word_str); } } }
@@ -3928,17 +3923,14 @@ static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b)ObjectClass *class_b = (ObjectClass *)b;X86CPUClass *cc_a =X86_CPU_CLASS (class_a);X86CPUClass *cc_b =X86_CPU_CLASS (class_b); -char *name_a, *name_b;int ret;if (cc_a->ordering != cc_b->ordering) { ret = cc_a->ordering - cc_b->ordering; }else { - name_a =x86_cpu_class_get_model_name (cc_a); - name_b =x86_cpu_class_get_model_name (cc_b); + g_autofree char *name_a = x86_cpu_class_get_model_name(cc_a); + g_autofree char *name_b = x86_cpu_class_get_model_name(cc_b); ret =strcmp (name_a, name_b); -g_free (name_a); -g_free (name_b); }return ret; }
@@ -3976,9 +3968,9 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) {ObjectClass *oc = data;X86CPUClass *cc =X86_CPU_CLASS (oc); -char *name =x86_cpu_class_get_model_name (cc); -char *desc =g_strdup (cc->model_description); -char *alias_of =x86_cpu_class_get_alias_of (cc); + g_autofree char *name = x86_cpu_class_get_model_name(cc); + g_autofree char *desc = g_strdup(cc->model_description); + g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc);if (!desc && alias_of) {if (cc->model && cc->model->version ==CPU_VERSION_AUTO ) {
@@ -3992,9 +3984,6 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) }qemu_printf ("x86 %-20s %-48s\n" , name, desc); -g_free (name); -g_free (desc); -g_free (alias_of); }/* list available CPU models and flags */
@@ -4433,7 +4422,7 @@ static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)static void x86_register_cpu_model_type (const char *name,X86CPUModel *model) { -char *typename =x86_cpu_type_name (name); + g_autofree char *typename = x86_cpu_type_name(name);TypeInfo ti = { .name = typename, .parent =TYPE_X86_CPU ,
@@ -4442,14 +4431,12 @@ static void x86_register_cpu_model_type(const char *name, X86CPUModel *model) };type_register (&ti); -g_free (typename); }static void x86_register_cpudef_types (X86CPUDefinition *def) {X86CPUModel *m;const X86CPUVersionDefinition *vdef; -char *name;/* AMD aliases are handled at runtime based on CPUID vendor, so * they shouldn't be set on the CPU model table.
@@ -4469,11 +4456,11 @@ static void x86_register_cpudef_types(X86CPUDefinition *def)for (vdef =x86_cpu_def_get_versions (def); vdef->version; vdef++) {X86CPUModel *m =g_new0 (X86CPUModel,1 ); + g_autofree char *name = +x86_cpu_versioned_model_name (def, vdef->version); m->cpudef = def; m->version = vdef->version; - name =x86_cpu_versioned_model_name (def, vdef->version);x86_register_cpu_model_type (name, m); -g_free (name);if (vdef->alias) {X86CPUModel *am =g_new0 (X86CPUModel,1 );
@@ -5545,9 +5532,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (xcc->host_cpuid_required) {if (!accel_uses_host_cpuid ()) { -char *name =x86_cpu_class_get_model_name (xcc); + g_autofree char *name = x86_cpu_class_get_model_name(xcc);error_setg (&local_err,"CPU model '%s' requires KVM" , name); -g_free (name); goto out; }
@@ -5663,10 +5649,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)/* Cache information initialization */ if (!cpu->legacy_cache) {if (!xcc->model || !xcc->model->cpudef->cache_info) { -char *name =x86_cpu_class_get_model_name (xcc); + g_autofree char *name = x86_cpu_class_get_model_name(xcc);error_setg (errp,"CPU model '%s' doesn't support legacy-cache=off" , name); -g_free (name);return ; } env->cache_info_cpuid2 = env->cache_info_cpuid4 = env->cache_info_amd =
Signature · 1 line
2.21.0
Quoted 7 lines · Eduardo Habkost
Get rid of 12 explicit
g_free()calls.Signed-off-by Eduardo Habkost <[email protected]>--- target/i386/cpu.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-)
The changes LGTM:
Reviewed-by Stefano Garzarella <[email protected]>
Thanks,
Stefano