mirror of https://github.com/xemu-project/xemu.git
qom: Don't make link NULL on object_property_set_link() failure
The error behavior of object_property_set_link() is dangerous. It sets the link property object to NULL if an error occurs. A setter function should either succeed or fail, it shouldn't leave the value NULL on failure. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
f5ec6704c7
commit
c6aed98334
29
qom/object.c
29
qom/object.c
|
@ -1080,27 +1080,28 @@ static Object *object_resolve_link(Object *obj, const char *name,
|
||||||
static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
|
static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
|
||||||
const char *name, Error **errp)
|
const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
|
Error *local_err = NULL;
|
||||||
Object **child = opaque;
|
Object **child = opaque;
|
||||||
Object *old_target;
|
Object *old_target = *child;
|
||||||
char *path;
|
Object *new_target = NULL;
|
||||||
|
char *path = NULL;
|
||||||
|
|
||||||
visit_type_str(v, &path, name, errp);
|
visit_type_str(v, &path, name, &local_err);
|
||||||
|
|
||||||
old_target = *child;
|
if (!local_err && strcmp(path, "") != 0) {
|
||||||
*child = NULL;
|
new_target = object_resolve_link(obj, name, path, &local_err);
|
||||||
|
|
||||||
if (strcmp(path, "") != 0) {
|
|
||||||
Object *target;
|
|
||||||
|
|
||||||
target = object_resolve_link(obj, name, path, errp);
|
|
||||||
if (target) {
|
|
||||||
object_ref(target);
|
|
||||||
*child = target;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
if (local_err) {
|
||||||
|
error_propagate(errp, local_err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_target) {
|
||||||
|
object_ref(new_target);
|
||||||
|
}
|
||||||
|
*child = new_target;
|
||||||
if (old_target != NULL) {
|
if (old_target != NULL) {
|
||||||
object_unref(old_target);
|
object_unref(old_target);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue