aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2016-08-02 11:41:41 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2016-08-03 18:44:57 +0200
commit0d4104e5760221547fad158bbbb655a4e4c22b50 (patch)
tree08d271d2e0af843ebe9c5075906e20224c2407f8
parentf04ec5afbb7d60a56863add800fd90ceee66f362 (diff)
downloadqemu-0d4104e5760221547fad158bbbb655a4e4c22b50.zip
qemu-0d4104e5760221547fad158bbbb655a4e4c22b50.tar.gz
qemu-0d4104e5760221547fad158bbbb655a4e4c22b50.tar.bz2
qdev: Fix use after free in qdev_init_nofail error path
Since 69382d8b (qdev: Fix object reference leak in case device.realize() fails), object_property_set_bool could release the object. The error path wants the type name, so hold an reference before realizing it. Cc: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Message-Id: <1470109301-12966-1-git-send-email-famz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--hw/core/qdev.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index ee4a083..5783442 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -354,12 +354,14 @@ void qdev_init_nofail(DeviceState *dev)
assert(!dev->realized);
+ object_ref(OBJECT(dev));
object_property_set_bool(OBJECT(dev), true, "realized", &err);
if (err) {
error_reportf_err(err, "Initialization of device %s failed: ",
object_get_typename(OBJECT(dev)));
exit(1);
}
+ object_unref(OBJECT(dev));
}
void qdev_machine_creation_done(void)