From aee9f7327ff4036ddfbd0a9041ddec0ddbdf630f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sun, 11 Mar 2018 16:52:40 -0400 Subject: [PATCH] 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 --- qemu/hw/core/machine.c | 9 ++++++++- qemu/include/hw/boards.h | 2 +- qemu/include/hw/i386/pc.h | 14 ++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/qemu/hw/core/machine.c b/qemu/hw/core/machine.c index 4681cb55..12d7559e 100644 --- a/qemu/hw/core/machine.c +++ b/qemu/hw/core/machine.c @@ -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, }; diff --git a/qemu/include/hw/boards.h b/qemu/include/hw/boards.h index 0d70f3fd..ce9ba5d7 100644 --- a/qemu/include/hw/boards.h +++ b/qemu/include/hw/boards.h @@ -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); diff --git a/qemu/include/hw/i386/pc.h b/qemu/include/hw/i386/pc.h index b4524eca..159b8b98 100644 --- a/qemu/include/hw/i386/pc.h +++ b/qemu/include/hw/i386/pc.h @@ -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) \