From: Stefan Hajnoczi <stefa...@redhat.com> 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-sta...@nongnu.org Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com> Signed-off-by: Andreas Färber <afaer...@suse.de> --- qdev-monitor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qdev-monitor.c b/qdev-monitor.c index b1ce26a..531b258 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -518,6 +518,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) { @@ -531,6 +532,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; } -- 1.8.1.4