qom: preserve object while unparenting it
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Jan 2013 13:12:30 +0000 (14:12 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 1 Feb 2013 21:53:09 +0000 (15:53 -0600)
Avoid that the object disappears after it's deleted from the QOM
composition tree, in case that was the only reference to it.

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>
qom/object.c

index e2002821725578f0edd09808ceed3cc863175d07..034f15cdec0699bd3dc0bb7df411256f1058bf6e 100644 (file)
@@ -361,12 +361,14 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
 
 void object_unparent(Object *obj)
 {
+    object_ref(obj);
     if (obj->parent) {
         object_property_del_child(obj->parent, obj, NULL);
     }
     if (obj->class->unparent) {
         (obj->class->unparent)(obj);
     }
+    object_unref(obj);
 }
 
 static void object_deinit(Object *obj, TypeImpl *type)