* [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure
@ 2014-03-04 14:28 Stefan Hajnoczi
2014-03-04 15:18 ` Eric Blake
2014-03-04 16:11 ` Andreas Färber
0 siblings, 2 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2014-03-04 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Faerber
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: Stefan Hajnoczi <stefanha@redhat.com>
---
qom/object.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 660859c..c88909c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1293,6 +1293,7 @@ void object_property_add_str(Object *obj, const char *name,
void (*set)(Object *, const char *, Error **),
Error **errp)
{
+ Error *local_err = NULL;
StringProperty *prop = g_malloc0(sizeof(*prop));
prop->get = get;
@@ -1302,7 +1303,11 @@ void object_property_add_str(Object *obj, const char *name,
get ? property_get_str : NULL,
set ? property_set_str : NULL,
property_release_str,
- prop, errp);
+ prop, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ }
}
typedef struct BoolProperty
@@ -1349,6 +1354,7 @@ void object_property_add_bool(Object *obj, const char *name,
void (*set)(Object *, bool, Error **),
Error **errp)
{
+ Error *local_err = NULL;
BoolProperty *prop = g_malloc0(sizeof(*prop));
prop->get = get;
@@ -1358,7 +1364,11 @@ void object_property_add_bool(Object *obj, const char *name,
get ? property_get_bool : NULL,
set ? property_set_bool : NULL,
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)
--
1.8.5.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure
2014-03-04 14:28 [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure Stefan Hajnoczi
@ 2014-03-04 15:18 ` Eric Blake
2014-03-04 16:11 ` Andreas Färber
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2014-03-04 15:18 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: Andreas Faerber
[-- Attachment #1: Type: text/plain, Size: 763 bytes --]
On 03/04/2014 07:28 AM, Stefan Hajnoczi wrote:
> 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: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> qom/object.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure
2014-03-04 14:28 [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure Stefan Hajnoczi
2014-03-04 15:18 ` Eric Blake
@ 2014-03-04 16:11 ` Andreas Färber
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2014-03-04 16:11 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: qemu-stable
Am 04.03.2014 15:28, schrieb Stefan Hajnoczi:
> 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: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> qom/object.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
Nice catch!
Thanks, applied to qom-next (and suggesting for qemu-stable):
https://github.com/afaerber/qemu-cpu/commits/qom-next
Regards,
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-04 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-04 14:28 [Qemu-devel] [PATCH] qom: avoid leaking str and bool properties on failure Stefan Hajnoczi
2014-03-04 15:18 ` Eric Blake
2014-03-04 16:11 ` Andreas Färber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).