qom: strdup() target_name on object_property_add_alias()
cover qom: strdup() target_name on object_property_add_alias()
This helps us avoid memory leaks when using object_property_add_alias(), as it is not practical for callers to save target_name to free it later.
Eduardo Habkost (2):
qom: strdup() target property name on object_property_add_alias()
qdev: Free property names after registering gpio aliases
hw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 qom: strdup() target property name on object_property_add_alias()
With this, object_property_add_alias() callers can safely free the target property name, like what already happens with the 'name' argument to all object_property_add*() functions.
--- qom/object.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
qom/object.c +3 -2
@@ -1689,7 +1689,7 @@ void object_property_add_uint64_ptr(Object *obj, const char *name,typedef struct {Object *target_obj; -const char *target_name; +char *target_name; }AliasProperty ; static void property_get_alias(Object *obj, struct Visitor *v, void *opaque,
@@ -1720,6 +1720,7 @@ static void property_release_alias(Object *obj, const char *name, void *opaque) {AliasProperty *prop = opaque; +g_free (prop->target_name);g_free (prop); }
@@ -1747,7 +1748,7 @@ void object_property_add_alias(Object *obj, const char *name, prop =g_malloc (sizeof (*prop)); prop->target_obj = target_obj; - prop->target_name = target_name; + prop->target_name =g_strdup (target_name); op = object_property_add(obj, name, prop_type, property_get_alias,
Signature · 1 line
2.1.0
PATCH 2/2 qdev: Free property names after registering gpio aliases
In reply to Eduardo HabkostNow that object_property_add_alias() strdup()s target_name, we can free the property names in qdev_pass_gpios().
--- hw/core/qdev.c | 2 ++ 1 file changed, 2 insertions(+)
hw/core/qdev.c +2 -0
@@ -563,6 +563,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,object_property_add_alias (OBJECT (container), propname,OBJECT (dev), propname, &error_abort); +g_free (propname); }for (i =0 ; i < ngl->num_out; i++) {const char *nm = ngl->name ? ngl->name :"unnamed-gpio-out" ;
@@ -571,6 +572,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,object_property_add_alias (OBJECT (container), propname,OBJECT (dev), propname, &error_abort); +g_free (propname); }QLIST_REMOVE (ngl, node);QLIST_INSERT_HEAD (&container->gpios, ngl, node);
Signature · 1 line
2.1.0
Quoted 11 lines · Eduardo Habkost
This helps us avoid memory leaks when using
object_property_add_alias(), as it is not practical for callers to savetarget_nameto free it later.Eduardo Habkost (2):
qom:strdup()target property name onobject_property_add_alias()
qdev: Free property names after registering gpio aliaseshw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
Good idea!
Am 09.04.2015 um 22:22 schrieb Paolo Bonzini:
Quoted 8 lines · Eduardo Habkost
Quoted 7 lines
This helps us avoid memory leaks when using
object_property_add_alias(), as it is not practical for callers to savetarget_nameto free it later.Eduardo Habkost (2):
qom:strdup()target property name onobject_property_add_alias()
qdev: Free property names after registering gpio aliases
Quoted 8 lines
Quoted 4 lines
hw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)Good idea!
Reviewed-by Paolo Bonzini <[email protected]>
Looks good to me in general, I'm just surprised that there are not more cleanups resulting out of this? At least my pc87312 series will need changes then. Will take a deeper look another day.
Regards,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Andreas Färber
AppliedAm 10.04.2015 um 00:48 schrieb Andreas Färber:
Quoted 14 lines
Am 09.04.2015 um 22:22 schrieb Paolo Bonzini:
Quoted 13 lines · Eduardo Habkost
Quoted 11 lines
This helps us avoid memory leaks when using
object_property_add_alias(), as it is not practical for callers to savetarget_nameto free it later.Eduardo Habkost (2):
qom:strdup()target property name onobject_property_add_alias()
qdev: Free property names after registering gpio aliaseshw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
Quoted 7 lines
Quoted 3 lines
Good idea!
Reviewed-by Paolo Bonzini <[email protected]>Looks good to me in general, I'm just surprised that there are not more cleanups resulting out of this? At least my pc87312 series will need changes then. Will take a deeper look another day.
Thanks, applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Quoted 17 lines · Andreas Färber
Am 10.04.2015 um 00:48 schrieb Andreas Färber:
Quoted 16 lines
Am 09.04.2015 um 22:22 schrieb Paolo Bonzini:
Quoted 15 lines · Eduardo Habkost
Quoted 11 lines
This helps us avoid memory leaks when using
object_property_add_alias(), as it is not practical for callers to savetarget_nameto free it later.Eduardo Habkost (2):
qom:strdup()target property name onobject_property_add_alias()
qdev: Free property names after registering gpio aliaseshw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)Good idea!
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Reviewed-by Paolo Bonzini <[email protected]>Looks good to me in general, I'm just surprised that there are not more cleanups resulting out of this? At least my pc87312 series will need changes then. Will take a deeper look another day.
Thanks, applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next
Thanks. Is it expected to appear in a pull request soon? This is needed for the X86CPU properties patch that's on the x86 queue.
Signature · 1 line
Eduardo
Quoted 14 lines · Eduardo Habkost
This helps us avoid memory leaks when using
object_property_add_alias(), as it is not practical for callers to savetarget_nameto free it later.Eduardo Habkost (2):
qom:strdup()target property name onobject_property_add_alias()
qdev: Free property names after registering gpio aliaseshw/core/qdev.c | 2 ++ qom/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)Signature · 1 line
2.1.0