mirror of https://github.com/proxmox/mirror_qemu
device_add: don't add a /peripheral link until init is complete
Otherwise we end up with a dangling reference which causes qdev_free() to fail. Reported-by: Michael Tsirkin <mst@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>master
parent
83f7d43a9e
commit
b2d4b3f7b8
|
@ -457,6 +457,16 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
id = qemu_opts_id(opts);
|
id = qemu_opts_id(opts);
|
||||||
if (id) {
|
if (id) {
|
||||||
qdev->id = id;
|
qdev->id = id;
|
||||||
|
}
|
||||||
|
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
|
||||||
|
qdev_free(qdev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (qdev_init(qdev) < 0) {
|
||||||
|
qerror_report(QERR_DEVICE_INIT_FAILED, driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (qdev->id) {
|
||||||
object_property_add_child(qdev_get_peripheral(), qdev->id,
|
object_property_add_child(qdev_get_peripheral(), qdev->id,
|
||||||
OBJECT(qdev), NULL);
|
OBJECT(qdev), NULL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -466,14 +476,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
||||||
OBJECT(qdev), NULL);
|
OBJECT(qdev), NULL);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
}
|
}
|
||||||
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
|
|
||||||
qdev_free(qdev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (qdev_init(qdev) < 0) {
|
|
||||||
qerror_report(QERR_DEVICE_INIT_FAILED, driver);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
qdev->opts = opts;
|
qdev->opts = opts;
|
||||||
return qdev;
|
return qdev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue