Patchwork [v2,03/12] qom: preserve object while unparenting it

login
register
mail settings
Submitter Paolo Bonzini
Date Jan. 21, 2013, 12:30 p.m.
Message ID <1358771422-14282-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/214130/
State New
Headers show

Comments

Paolo Bonzini - Jan. 21, 2013, 12:30 p.m.
Avoid that the object disappears after it's deleted from the QOM
composition tree, in case that was the only reference to it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c | 2 ++
 1 file changed, 2 insertions(+)
Andreas Färber - Jan. 21, 2013, 1:03 p.m.
Am 21.01.2013 13:30, schrieb Paolo Bonzini:
> Avoid that the object disappears after it's deleted from the QOM
> composition tree, in case that was the only reference to it.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Acked-by: Andreas Färber <afaerber@suse.de>

Andreas

Patch

diff --git a/qom/object.c b/qom/object.c
index 03e6f24..1a123da 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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)