diff mbox

[01/10] qom: add, remove of link property need to ref, unref its target

Message ID 1345801763-24227-2-git-send-email-qemulist@gmail.com
State New
Headers show

Commit Message

pingfan liu Aug. 24, 2012, 9:49 a.m. UTC
From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>

Currently, link property's target is only managed by
object_set_link_property(). This will raise such issue that when
the property is finalized, its target has no opportunity to release.

Fix this issue by introduce object_finalize_link_property()
In correspond, ref target when adding link prpoerty.

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 qom/object.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini Aug. 24, 2012, 2:52 p.m. UTC | #1
Il 24/08/2012 11:49, Liu Ping Fan ha scritto:
> From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> 
> Currently, link property's target is only managed by
> object_set_link_property(). This will raise such issue that when
> the property is finalized, its target has no opportunity to release.
> 
> Fix this issue by introduce object_finalize_link_property()
> In correspond, ref target when adding link prpoerty.
> 
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---

This patch is fine, but it is at the wrong place in the series.  It will
cause an assertion failure due to the unbroken circular reference.

Paolo
diff mbox

Patch

diff --git a/qom/object.c b/qom/object.c
index a552be2..00f98d7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -957,6 +957,16 @@  static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
     }
 }
 
+static void object_finalize_link_property(Object *obj, const char *name,
+                                           void *opaque)
+{
+    Object **child = opaque;
+
+    if (*child != NULL) {
+        object_unref(*child);
+    }
+}
+
 void object_property_add_link(Object *obj, const char *name,
                               const char *type, Object **child,
                               Error **errp)
@@ -968,8 +978,10 @@  void object_property_add_link(Object *obj, const char *name,
     object_property_add(obj, name, full_type,
                         object_get_link_property,
                         object_set_link_property,
-                        NULL, child, errp);
-
+                        object_finalize_link_property, child, errp);
+    if (*child != NULL) {
+        object_ref(*child);
+    }
     g_free(full_type);
 }