[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 2/5] qom: don't make link NULL on object_property
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v4 2/5] qom: don't make link NULL on object_property_set_link() failure |
Date: |
Tue, 18 Mar 2014 13:49:40 +0100 |
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 <address@hidden>
---
qom/object.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index da49474..25fc04c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1079,27 +1079,28 @@ static Object *object_resolve_link(Object *obj, const
char *name,
static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
+ Error *local_err = NULL;
Object **child = opaque;
- Object *old_target;
- char *path;
-
- visit_type_str(v, &path, name, errp);
+ Object *old_target = *child;
+ Object *new_target = NULL;
+ char *path = NULL;
- old_target = *child;
- *child = NULL;
+ visit_type_str(v, &path, name, &local_err);
- if (strcmp(path, "") != 0) {
- Object *target;
-
- target = object_resolve_link(obj, name, path, errp);
- if (target) {
- object_ref(target);
- *child = target;
- }
+ if (!local_err && strcmp(path, "") != 0) {
+ new_target = object_resolve_link(obj, name, path, &local_err);
}
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) {
object_unref(old_target);
}
--
1.8.5.3
- [Qemu-devel] [PATCH v4 0/5] v4:, Stefan Hajnoczi, 2014/03/18
- [Qemu-devel] [PATCH v4 1/5] qom: split object_property_set_link(), Stefan Hajnoczi, 2014/03/18
- [Qemu-devel] [PATCH v4 5/5] virtio-rng: avoid default_backend refcount leak, Stefan Hajnoczi, 2014/03/18
- [Qemu-devel] [PATCH v4 3/5] qom: make QOM link property unref optional, Stefan Hajnoczi, 2014/03/18
- [Qemu-devel] [PATCH v4 4/5] qom: add check() argument to object_property_add_link(), Stefan Hajnoczi, 2014/03/18
- [Qemu-devel] [PATCH v4 2/5] qom: don't make link NULL on object_property_set_link() failure,
Stefan Hajnoczi <=
- Re: [Qemu-devel] [PATCH v4 0/5] v4:, Stefan Hajnoczi, 2014/03/18