Skip to contentSkip to conversation

qom: In function object_set_link_property(), first call object_ref(), then object_unref().

PATCH Applied [email protected] 4 participants 5 messages Feb 22, 2012 – Feb 24, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qom: In function object_set_link_property(), first call object_ref(), then object_unref().

From: Alexander Barabash <[email protected]>

In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object.

In the new implementation, this is fixed.

---
 qom/object.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
qom/object.c +7 -4
index 941c291..e6591e1 100644
@@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
     Object **child = opaque;
+    Object *old_target;
     bool ambiguous = false;
     const char *type;
     char *path;
@@ -901,10 +902,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
 
     visit_type_str(v, &path, name, errp);
 
-    if (*child) {
-        object_unref(*child);
-        *child = NULL;
-    }
+    old_target = *child;
+    *child = NULL;
 
     if (strcmp(path, "") != 0) {
         Object *target;
@@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
     }
 
     g_free(path);
+
+    if (old_target != NULL) {
+        object_unref(old_target);
+    }
 }
 
 void object_property_add_link(Object *obj, const char *name,
Signature · 1 line
1.7.5.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · On 02/22/2012 06:22 PM, [email protected] wrote:

From: Alexander Barabash <[email protected]>

In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object.

In the new implementation, this is fixed.

---
 qom/object.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
qom/object.c +3 -4
index 941c291..e6591e1 100644
@@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
     Object **child = opaque;
+    Object *old_target;
     bool ambiguous = false;
     const char *type;
     char *path;
@@ -901,10 +902,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
 
     visit_type_str(v, &path, name, errp);
 
-    if (*child) {
-        object_unref(*child);
-        *child = NULL;
-    }
+    old_target = *child;
+    *child = NULL;
 
     if (strcmp(path, "") != 0) {
         Object *target;

qom/object.c static void object_set_link_property(Object *obj, Visitor *v, void *opaque, · line 938

Quoted 10 lines
qom/object.c +4 -0
@@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
     }
 
     g_free(path);
+
+    if (old_target != NULL) {
+        object_unref(old_target);
+    }
 }
 
 void object_property_add_link(Object *obj, const char *name,
#2 lore raw
Quoted 49 lines · Paolo Bonzini
Quoted 48 lines · On 02/22/2012 06:22 PM, [email protected] wrote:

From: Alexander Barabash<[email protected]>

In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object.

In the new implementation, this is fixed.

---
  qom/object.c |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)
qom/object.c +7 -4
index 941c291..e6591e1 100644
@@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
                                       const char *name, Error **errp)
  {
      Object **child = opaque;
+    Object *old_target;
      bool ambiguous = false;
      const char *type;
      char *path;
@@ -901,10 +902,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
 
      visit_type_str(v,&path, name, errp);
 
-    if (*child) {
-        object_unref(*child);
-        *child = NULL;
-    }
+    old_target = *child;
+    *child = NULL;
 
      if (strcmp(path, "") != 0) {
          Object *target;
@@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
      }
 
      g_free(path);
+
+    if (old_target != NULL) {
+        object_unref(old_target);
+    }
  }
 
Quoted 2 lines

qom/object.c static void object_set_link_property(Object *obj, Visitor *v, void *opaque, · line 938

Quoted 1 line
qom/object.c +0 -0
  void object_property_add_link(Object *obj, const char *name,

Sorry, I did not figure out yet how to add the "v2" to the subject line. )) Alex

#3 lore raw
Quoted 1 line · Alexander Barabash

Sorry, I did not figure out yet how to add the "v2" to the subject line. ))

git send-email --subject-prefix=PATCHv2

or

git send-email --annotate, then in the editor that pops up, add v2 in the appropriate place

there's probably other possibilities as well.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
In reply to [email protected]
Quoted 9 lines · On 02/22/2012 11:22 AM, [email protected] wrote:

From: Alexander Barabash<[email protected]>

In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object.

In the new implementation, this is fixed.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 40 lines
---
  qom/object.c |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)
qom/object.c +7 -4
index 941c291..e6591e1 100644
@@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
                                       const char *name, Error **errp)
  {
      Object **child = opaque;
+    Object *old_target;
      bool ambiguous = false;
      const char *type;
      char *path;
@@ -901,10 +902,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
 
      visit_type_str(v,&path, name, errp);
 
-    if (*child) {
-        object_unref(*child);
-        *child = NULL;
-    }
+    old_target = *child;
+    *child = NULL;
 
      if (strcmp(path, "") != 0) {
          Object *target;
@@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
      }
 
      g_free(path);
+
+    if (old_target != NULL) {
+        object_unref(old_target);
+    }
  }
 
  void object_property_add_link(Object *obj, const char *name,