summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2013-09-10 18:21:08 +0200
committerAndreas Färber <afaerber@suse.de>2013-11-05 18:06:24 +0100
commitee6abeb6ec08473713848ce9028110f1684853b7 (patch)
tree5fc29c54230425e4a26d9723dadd48f4c89b18bc
parent2fa4e56d88aa0039062bbc7f9a88e9f90c77ed94 (diff)
downloadqemu-ee6abeb6ec08473713848ce9028110f1684853b7.zip
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>
-rw-r--r--qdev-monitor.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 753bab7545..9099d3d8f1 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
}