提交 a01aedc8 编写于 作者: S Stefan Hajnoczi 提交者: Andreas Färber

qom: Avoid leaking str and bool properties on failure

When object_property_add_str() and object_property_add_bool() fail, they
leak their internal StringProperty and BoolProperty structs.  Remember
to free the structs on error.

Luckily this is a low-impact memory leak since most QOM properties are
static qdev properties that will never take the error case.
object_property_add() only fails if the property name is already in use.
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: NAndreas Färber <afaerber@suse.de>
上级 7b030949
...@@ -1293,6 +1293,7 @@ void object_property_add_str(Object *obj, const char *name, ...@@ -1293,6 +1293,7 @@ void object_property_add_str(Object *obj, const char *name,
void (*set)(Object *, const char *, Error **), void (*set)(Object *, const char *, Error **),
Error **errp) Error **errp)
{ {
Error *local_err = NULL;
StringProperty *prop = g_malloc0(sizeof(*prop)); StringProperty *prop = g_malloc0(sizeof(*prop));
prop->get = get; prop->get = get;
...@@ -1302,7 +1303,11 @@ void object_property_add_str(Object *obj, const char *name, ...@@ -1302,7 +1303,11 @@ void object_property_add_str(Object *obj, const char *name,
get ? property_get_str : NULL, get ? property_get_str : NULL,
set ? property_set_str : NULL, set ? property_set_str : NULL,
property_release_str, property_release_str,
prop, errp); prop, &local_err);
if (local_err) {
error_propagate(errp, local_err);
g_free(prop);
}
} }
typedef struct BoolProperty typedef struct BoolProperty
...@@ -1349,6 +1354,7 @@ void object_property_add_bool(Object *obj, const char *name, ...@@ -1349,6 +1354,7 @@ void object_property_add_bool(Object *obj, const char *name,
void (*set)(Object *, bool, Error **), void (*set)(Object *, bool, Error **),
Error **errp) Error **errp)
{ {
Error *local_err = NULL;
BoolProperty *prop = g_malloc0(sizeof(*prop)); BoolProperty *prop = g_malloc0(sizeof(*prop));
prop->get = get; prop->get = get;
...@@ -1358,7 +1364,11 @@ void object_property_add_bool(Object *obj, const char *name, ...@@ -1358,7 +1364,11 @@ void object_property_add_bool(Object *obj, const char *name,
get ? property_get_bool : NULL, get ? property_get_bool : NULL,
set ? property_set_bool : NULL, set ? property_set_bool : NULL,
property_release_bool, property_release_bool,
prop, errp); prop, &local_err);
if (local_err) {
error_propagate(errp, local_err);
g_free(prop);
}
} }
static char *qdev_get_type(Object *obj, Error **errp) static char *qdev_get_type(Object *obj, Error **errp)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册