@@ -295,7 +295,7 @@ PCIBus *pci_bus_new(DeviceState *parent, const char
*name,
PCIBus *bus;
bus = g_malloc0(sizeof(*bus));
- bus->qbus.qdev_allocated = 1;
+ bus->qbus.glib_allocated = true;
pci_bus_new_inplace(bus, parent, name, address_space_mem,
address_space_io, devfn_min);
return bus;
@@ -423,7 +423,7 @@ BusState *qbus_create(const char *typename,
DeviceState *parent, const char *nam
BusState *bus;
bus = BUS(object_new(typename));
- bus->qdev_allocated = 1;
+ bus->qom_allocated = true;
do_qbus_create_inplace(bus, typename, parent, name);
return bus;
}
@@ -443,8 +443,13 @@ void qbus_free(BusState *bus)
qemu_unregister_reset(qbus_reset_all_fn, bus);
}
g_free((void*)bus->name);
- if (bus->qdev_allocated) {
- g_free(bus);
+ if (bus->qom_allocated) {
+ object_delete(OBJECT(bus));
+ } else {
+ object_finalize(OBJECT(bus));
+ if (bus->glib_allocated) {
+ g_free(bus);
+ }
}
}
@@ -100,12 +100,19 @@ struct BusClass {
int (*reset)(BusState *bus);
};
+/**
+ * BusState:
+ * @qom_allocated: Indicates whether the object was allocated by QOM.
+ * @glib_allocated: Indicates whether the object was initialized in-place
+ * yet is expected to be freed with g_free().
+ */
struct BusState {
Object obj;
DeviceState *parent;
const char *name;
int allow_hotplug;
- int qdev_allocated;
+ bool qom_allocated;
+ bool glib_allocated;
QTAILQ_HEAD(ChildrenHead, DeviceState) children;
QLIST_ENTRY(BusState) sibling;
};
@@ -274,7 +274,7 @@ static void main_system_bus_create(void)
main_system_bus = g_malloc0(system_bus_info.instance_size);
qbus_create_inplace(main_system_bus, TYPE_SYSTEM_BUS, NULL,
"main-system-bus");
- main_system_bus->qdev_allocated = 1;
+ main_system_bus->glib_allocated = true;
}
BusState *sysbus_get_default(void)