From: Stefan Hajnoczi Date: Tue, 10 Sep 2013 16:21:08 +0000 (+0200) Subject: qdev-monitor: Unref device when device_add fails X-Git-Tag: v1.6.2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03060dc086ec8a75929b7bb58df9e67a305a810d;p=thirdparty%2Fqemu.git 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 Reviewed-by: Eric Blake Signed-off-by: Andreas Färber (cherry picked from commit ee6abeb6ec08473713848ce9028110f1684853b7) Signed-off-by: Michael Roth --- diff --git a/qdev-monitor.c b/qdev-monitor.c index bb2e1b6ab9a..1b2c606f43e 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; }