All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] pl031: add finalize function to avoid memleaks
@ 2020-02-04  2:05 pannengyuan
  2020-02-04  7:20 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: pannengyuan @ 2020-02-04  2:05 UTC (permalink / raw)
  To: peter.maydell
  Cc: Euler Robot, qemu-arm, Pan Nengyuan, zhang.zhanghailiang, qemu-devel

From: Pan Nengyuan <pannengyuan@huawei.com>

There is a memory leak when we call 'device_list_properties' with
typename = pl031. It's easy to reproduce as follow:

  virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "pl031"}}'

The memory leak stack:
  Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f6e0925a970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
    #1 0x7f6e06f4d49d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
    #2 0x564a0f7654ea in timer_new_full /mnt/sdb/qemu/include/qemu/timer.h:530
    #3 0x564a0f76555d in timer_new /mnt/sdb/qemu/include/qemu/timer.h:551
    #4 0x564a0f765589 in timer_new_ns /mnt/sdb/qemu/include/qemu/timer.h:569
    #5 0x564a0f76747d in pl031_init /mnt/sdb/qemu/hw/rtc/pl031.c:198
    #6 0x564a0fd4a19d in object_init_with_type /mnt/sdb/qemu/qom/object.c:360
    #7 0x564a0fd4b166 in object_initialize_with_type /mnt/sdb/qemu/qom/object.c:467
    #8 0x564a0fd4c8e6 in object_new_with_type /mnt/sdb/qemu/qom/object.c:636
    #9 0x564a0fd4c98e in object_new /mnt/sdb/qemu/qom/object.c:646
    #10 0x564a0fc69d43 in qmp_device_list_properties /mnt/sdb/qemu/qom/qom-qmp-cmds.c:204
    #11 0x564a0ef18e64 in qdev_device_help /mnt/sdb/qemu/qdev-monitor.c:278

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
Changes V2 to V1:
- Delay the timer_new until realize instead of putting it into instance_init, since the pl031 can't be hotplugged(suggested by Peter Maydell).
---
 hw/rtc/pl031.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/rtc/pl031.c b/hw/rtc/pl031.c
index ae47f09635..0b9253eb30 100644
--- a/hw/rtc/pl031.c
+++ b/hw/rtc/pl031.c
@@ -190,7 +190,11 @@ static void pl031_init(Object *obj)
     qemu_get_timedate(&tm, 0);
     s->tick_offset = mktimegm(&tm) -
         qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
+}
 
+static void pl031_realize(DeviceState *dev, Error **errp)
+{
+    PL031State *s = PL031(dev);
     s->timer = timer_new_ns(rtc_clock, pl031_interrupt, s);
 }
 
@@ -321,6 +325,7 @@ static void pl031_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_pl031;
+    dc->realize = pl031_realize;
     device_class_set_props(dc, pl031_properties);
 }
 
-- 
2.21.0.windows.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] pl031: add finalize function to avoid memleaks
  2020-02-04  2:05 [PATCH v2] pl031: add finalize function to avoid memleaks pannengyuan
@ 2020-02-04  7:20 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-04  7:20 UTC (permalink / raw)
  To: pannengyuan, peter.maydell
  Cc: qemu-devel, qemu-arm, zhang.zhanghailiang, Euler Robot

On 2/4/20 3:05 AM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> There is a memory leak when we call 'device_list_properties' with
> typename = pl031. It's easy to reproduce as follow:
> 
>    virsh qemu-monitor-command vm1 --pretty '{"execute": "device-list-properties", "arguments": {"typename": "pl031"}}'
> 
> The memory leak stack:
>    Direct leak of 48 byte(s) in 1 object(s) allocated from:
>      #0 0x7f6e0925a970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
>      #1 0x7f6e06f4d49d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
>      #2 0x564a0f7654ea in timer_new_full /mnt/sdb/qemu/include/qemu/timer.h:530
>      #3 0x564a0f76555d in timer_new /mnt/sdb/qemu/include/qemu/timer.h:551
>      #4 0x564a0f765589 in timer_new_ns /mnt/sdb/qemu/include/qemu/timer.h:569
>      #5 0x564a0f76747d in pl031_init /mnt/sdb/qemu/hw/rtc/pl031.c:198
>      #6 0x564a0fd4a19d in object_init_with_type /mnt/sdb/qemu/qom/object.c:360
>      #7 0x564a0fd4b166 in object_initialize_with_type /mnt/sdb/qemu/qom/object.c:467
>      #8 0x564a0fd4c8e6 in object_new_with_type /mnt/sdb/qemu/qom/object.c:636
>      #9 0x564a0fd4c98e in object_new /mnt/sdb/qemu/qom/object.c:646
>      #10 0x564a0fc69d43 in qmp_device_list_properties /mnt/sdb/qemu/qom/qom-qmp-cmds.c:204
>      #11 0x564a0ef18e64 in qdev_device_help /mnt/sdb/qemu/qdev-monitor.c:278
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> ---
> Changes V2 to V1:
> - Delay the timer_new until realize instead of putting it into instance_init, since the pl031 can't be hotplugged(suggested by Peter Maydell).
> ---
>   hw/rtc/pl031.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/hw/rtc/pl031.c b/hw/rtc/pl031.c
> index ae47f09635..0b9253eb30 100644
> --- a/hw/rtc/pl031.c
> +++ b/hw/rtc/pl031.c
> @@ -190,7 +190,11 @@ static void pl031_init(Object *obj)
>       qemu_get_timedate(&tm, 0);
>       s->tick_offset = mktimegm(&tm) -
>           qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
> +}
>   
> +static void pl031_realize(DeviceState *dev, Error **errp)
> +{
> +    PL031State *s = PL031(dev);
>       s->timer = timer_new_ns(rtc_clock, pl031_interrupt, s);
>   }
>   
> @@ -321,6 +325,7 @@ static void pl031_class_init(ObjectClass *klass, void *data)
>       DeviceClass *dc = DEVICE_CLASS(klass);
>   
>       dc->vmsd = &vmstate_pl031;
> +    dc->realize = pl031_realize;
>       device_class_set_props(dc, pl031_properties);
>   }
>   
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-04  7:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04  2:05 [PATCH v2] pl031: add finalize function to avoid memleaks pannengyuan
2020-02-04  7:20 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.