]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qom: object: move unparenting to the child property's release callback
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 11 Jun 2014 09:57:38 +0000 (11:57 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 17 Aug 2014 21:25:24 +0000 (23:25 +0200)
This ensures that the unparent callback is called automatically
when the parent object is finalized.

Note that there's no need to keep a reference neither in
object_unparent nor in object_finalize_child_property.  The
reference held by the child property itself will do.

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qom/object.c

index f301bc2abbbcb91ae0c3b10141ef3a52b17254e6..1b00831efce662275a583ffbd3aab8c44015c4f3 100644 (file)
@@ -387,19 +387,9 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
 
 void object_unparent(Object *obj)
 {
-    if (!obj->parent) {
-        return;
-    }
-
-    object_ref(obj);
-    if (obj->class->unparent) {
-        (obj->class->unparent)(obj);
-    }
     if (obj->parent) {
         object_property_del_child(obj->parent, obj, NULL);
-        obj->parent = NULL;
     }
-    object_unref(obj);
 }
 
 static void object_deinit(Object *obj, TypeImpl *type)
@@ -1042,6 +1032,10 @@ static void object_finalize_child_property(Object *obj, const char *name,
 {
     Object *child = opaque;
 
+    if (child->class->unparent) {
+        (child->class->unparent)(child);
+    }
+    child->parent = NULL;
     object_unref(child);
 }