summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-11-23 09:47:12 +0100
committerDoug Goldstein <cardoe@cardoe.com>2012-12-13 15:31:59 -0600
commit8a08672c2c2e5243ee03bb0b43f19c0539191477 (patch)
tree72e8635292fe9e94d0445fcc9c924fd2c9b36050
parentPPC: Fix missing TRACE exception (diff)
downloadqemu-kvm-8a08672c2c2e5243ee03bb0b43f19c0539191477.tar.gz
qemu-kvm-8a08672c2c2e5243ee03bb0b43f19c0539191477.tar.bz2
qemu-kvm-8a08672c2c2e5243ee03bb0b43f19c0539191477.zip
qom: fix refcount of non-heap-allocated objects
The reference count for embedded objects is always one too low, because object_initialize_with_type returns with zero references to the object. This causes premature finalization of the object (or an assertion failure) after calling object_ref to add an extra reference and object_unref to remove it. The fix is to move the initial object_ref call from object_new_with_type to object_initialize_with_type. Acked-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 764b63125a77dab54ed405d493452a4e05679c2e) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> (cherry picked from commit f05a3da4e00d24c4540811e6fff2c4f0484771bd)
-rw-r--r--qom/object.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/qom/object.c b/qom/object.c
index f33e84da7..549931809 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -307,6 +307,7 @@ void object_initialize_with_type(void *data, TypeImpl *type)
memset(obj, 0, type->instance_size);
obj->class = type->class;
+ object_ref(obj);
QTAILQ_INIT(&obj->properties);
object_init_with_type(obj, type);
}
@@ -395,7 +396,6 @@ Object *object_new_with_type(Type type)
obj = g_malloc(type->instance_size);
object_initialize_with_type(obj, type);
- object_ref(obj);
return obj;
}