提交 abed886e 编写于 作者: P Paolo Bonzini 提交者: Andreas Färber

qdev: Free QemuOpts when the QOM path goes away

Otherwise there is a race where the DEVICE_DELETED event has been sent but
attempts to reuse the ID will fail.

Note that similar races exist for other QemuOpts, which this patch
does not attempt to fix.

For example, if the device is a block device, then unplugging it also
deletes its backend.  However, this backend's get deleted in
drive_info_del(), which is only called when properties are
destroyed.  Just like device_finalize(), drive_info_del() is called
some time after DEVICE_DELETED is sent.  A separate patch series has
been sent to plug this other bug.  Character devices also have yet to
be fixed.
Reported-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NAndreas Färber <afaerber@suse.de>
上级 7746abd8
...@@ -1206,7 +1206,6 @@ static void device_finalize(Object *obj) ...@@ -1206,7 +1206,6 @@ static void device_finalize(Object *obj)
NamedGPIOList *ngl, *next; NamedGPIOList *ngl, *next;
DeviceState *dev = DEVICE(obj); DeviceState *dev = DEVICE(obj);
qemu_opts_del(dev->opts);
QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {
QLIST_REMOVE(ngl, node); QLIST_REMOVE(ngl, node);
...@@ -1254,6 +1253,9 @@ static void device_unparent(Object *obj) ...@@ -1254,6 +1253,9 @@ static void device_unparent(Object *obj)
qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_abort); qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_abort);
g_free(path); g_free(path);
} }
qemu_opts_del(dev->opts);
dev->opts = NULL;
} }
static void device_class_init(ObjectClass *class, void *data) static void device_class_init(ObjectClass *class, void *data)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册