On Fri, Oct 30, 2020 at 2:09 AM Eduardo Habkost <ehabk...@redhat.com> wrote:

> Reuse function instead of calling object_property_add() directly.
> We need to hack ObjectProperty.release to make sure we will free
> the array property.
>
> Signed-off-by: Eduardo Habkost <ehabk...@redhat.com>
>

that seems to be right, but could use more eyes... somebody may have an
idea of simplification.

Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com>

---
> Cc: Paolo Bonzini <pbonz...@redhat.com>
> Cc: "Daniel P. Berrangé" <berra...@redhat.com>
> Cc: Eduardo Habkost <ehabk...@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  hw/core/qdev-properties.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 1f06dfb5d5..4fec9cb73b 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -600,7 +600,6 @@ static ArrayElementProperty *array_element_new(Object
> *obj,
>  {
>      char *propname = g_strdup_printf("%s[%d]", arrayname, index);
>      ArrayElementProperty *arrayprop = g_new0(ArrayElementProperty, 1);
> -    arrayprop->release = array_len_prop->arrayinfo->release;
>      arrayprop->propname = propname;
>      arrayprop->prop.info = array_len_prop->arrayinfo;
>      arrayprop->prop.name = propname;
> @@ -632,12 +631,12 @@ static void object_property_add_array_element(Object
> *obj,
>                                                Property *array_len_prop,
>                                                ArrayElementProperty *prop)
>  {
> -    object_property_add(obj, prop->prop.name,
> -                        prop->prop.info->name,
> -                        static_prop_getter(prop->prop.info),
> -                        static_prop_setter(prop->prop.info),
> -                        array_element_release,
> -                        prop);
> +    ObjectProperty *op = object_property_add_static(obj, &prop->prop);
> +
> +    assert((void *)prop == (void *)&prop->prop);
> +    prop->release = op->release;
> +    /* array_element_release() will call the original release function */
> +    op->release = array_element_release;
>  }
>
>  static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
> --
> 2.28.0
>
>
>

-- 
Marc-André Lureau

Reply via email to