qdev-monitor: Unref device when device_add fails

qdev_device_add() leaks the created device upon failure.  I suspect this
problem crept in because qdev_free() unparents the device but does not
drop a reference - confusing name.

Cc: qemu-stable@nongnu.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Stefan Hajnoczi 2013-09-10 18:21:08 +02:00 committed by Andreas Färber
parent 2fa4e56d88
commit ee6abeb6ec

View File

@ -527,6 +527,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
}
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
qdev_free(qdev);
object_unref(OBJECT(qdev));
return NULL;
}
if (qdev->id) {
@ -540,6 +541,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
g_free(name);
}
if (qdev_init(qdev) < 0) {
object_unref(OBJECT(qdev));
qerror_report(QERR_DEVICE_INIT_FAILED, driver);
return NULL;
}