mirror of
https://github.com/qemu/qemu.git
synced 2025-08-09 10:25:06 +00:00
qom: In function object_set_link_property(), first call object_ref(), then object_unref().
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. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alexander Barabash <alexander_barabash@mentor.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
adbbdf2484
commit
f0cdc966fb
11
qom/object.c
11
qom/object.c
@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
|
|||||||
const char *name, Error **errp)
|
const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
Object **child = opaque;
|
Object **child = opaque;
|
||||||
|
Object *old_target;
|
||||||
bool ambiguous = false;
|
bool ambiguous = false;
|
||||||
const char *type;
|
const char *type;
|
||||||
char *path;
|
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);
|
visit_type_str(v, &path, name, errp);
|
||||||
|
|
||||||
if (*child) {
|
old_target = *child;
|
||||||
object_unref(*child);
|
*child = NULL;
|
||||||
*child = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(path, "") != 0) {
|
if (strcmp(path, "") != 0) {
|
||||||
Object *target;
|
Object *target;
|
||||||
@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
|
||||||
|
if (old_target != NULL) {
|
||||||
|
object_unref(old_target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void object_property_add_link(Object *obj, const char *name,
|
void object_property_add_link(Object *obj, const char *name,
|
||||||
|
Loading…
Reference in New Issue
Block a user