machine: use class base init generated name

machine_class_base_init() member name is allocated by
machine_class_base_init(), but not freed by
machine_class_finalize().  Simply freeing there doesn't work,
because DEFINE_PC_MACHINE() overwrites it with a literal string.

Fix DEFINE_PC_MACHINE() not to overwrite it, and add the missing
free to machine_class_finalize().

Backports commit 8ea753718b2d1a42e9ce7b8db9f5e4e1f330e827 from qemu
This commit is contained in:
Marc-André Lureau 2018-03-11 16:52:40 -04:00 committed by Lioncash
parent 8648b1df4f
commit aee9f7327f
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 19 additions and 6 deletions

View file

@ -26,6 +26,13 @@ static void machine_class_base_init(struct uc_struct *uc, ObjectClass *oc, void
}
}
static void machine_class_finalize(struct uc_struct *uc, ObjectClass *klass, void *data)
{
MachineClass *mc = MACHINE_CLASS(uc, klass);
g_free(mc->name);
}
static void machine_initfn(struct uc_struct *uc, Object *obj, void *opaque)
{
}
@ -50,7 +57,7 @@ static const TypeInfo machine_info = {
NULL,
machine_class_base_init,
NULL,
machine_class_finalize,
true,
};

View file

@ -84,7 +84,7 @@ struct MachineClass {
ObjectClass parent_class;
/*< public >*/
const char *name;
char *name;
int (*init)(struct uc_struct *uc, MachineState *state);
void (*reset)(void);

View file

@ -54,14 +54,20 @@ void x86_cpu_register_types(struct uc_struct *uc);
MachineClass *mc = MACHINE_CLASS(uc, oc); \
mc->max_cpus = 255; \
mc->is_default = 1; \
mc->name = namestr; \
mc->init = initfn; \
mc->arch = UC_ARCH_X86; \
} \
static const TypeInfo pc_machine_type_##suffix = { \
.name = namestr TYPE_MACHINE_SUFFIX, \
.parent = TYPE_PC_MACHINE, \
.class_init = pc_machine_##suffix##_class_init, \
namestr TYPE_MACHINE_SUFFIX, \
TYPE_PC_MACHINE, \
0, \
0, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
pc_machine_##suffix##_class_init, \
}; \
void pc_machine_init_##suffix(struct uc_struct *uc); \
void pc_machine_init_##suffix(struct uc_struct *uc) \