qdev has this quirk that it owns a seemingly arbitrary QemuOpts pointer. That's because qdev expects a static string for the id (which really makes no sense since ids are supposed to be provided by the user). Instead of managing just the id pointer, we currently take ownership of the entire QemuOpts structure that was used to create the device just to keep the name around.
Just strdup the pointer we actually need. Signed-off-by: Anthony Liguori <aligu...@us.ibm.com> --- hw/qdev.c | 3 ++- hw/qdev.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index aeebdb9..41ed872 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -107,7 +107,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info, const } dev->instance_id_alias = -1; dev->state = DEV_STATE_CREATED; - dev->id = id; + dev->id = g_strdup(id); return dev; } @@ -414,6 +414,7 @@ void qdev_free(DeviceState *dev) qemu_opts_del(dev->opts); } QLIST_REMOVE(dev, sibling); + g_free(dev->id); for (prop = dev->info->props; prop && prop->name; prop++) { if (prop->info->free) { prop->info->free(dev, prop); diff --git a/hw/qdev.h b/hw/qdev.h index 626a1b6..c86736a 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -30,7 +30,7 @@ enum { /* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState { - const char *id; + char *id; enum DevState state; QemuOpts *opts; int hotplugged; -- 1.7.4.1