Re: [PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks

2020-02-05 Thread Alistair Francis
On Tue, Feb 4, 2020 at 11:09 PM  wrote:
>
> From: Pan Nengyuan 
>
> There is a memory leak when we call 'device_list_properties' with typename = 
> stm32f2xx_timer. It's easy to reproduce as follow:
>
> virsh qemu-monitor-command vm1 --pretty '{"execute": 
> "device-list-properties", "arguments": {"typename": "stm32f2xx_timer"}}'
>
> This patch delay timer_new to fix this memleaks.
>
> Reported-by: Euler Robot 
> Signed-off-by: Pan Nengyuan 
> Cc: Alistair Francis 

Reviewed-by: Alistair Francis 

Alistair

> ---
>  hw/timer/stm32f2xx_timer.c | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
> index fb370ce0f0..06ec8a02c2 100644
> --- a/hw/timer/stm32f2xx_timer.c
> +++ b/hw/timer/stm32f2xx_timer.c
> @@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
>  memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
>"stm32f2xx_timer", 0x400);
>  sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
> +}
>
> +static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
> +{
> +STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
>  s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, 
> s);
>  }
>
> @@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass 
> *klass, void *data)
>  dc->reset = stm32f2xx_timer_reset;
>  device_class_set_props(dc, stm32f2xx_timer_properties);
>  dc->vmsd = &vmstate_stm32f2xx_timer;
> +dc->realize = stm32f2xx_timer_realize;
>  }
>
>  static const TypeInfo stm32f2xx_timer_info = {
> --
> 2.21.0.windows.1
>
>
>



Re: [PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks

2020-02-05 Thread Philippe Mathieu-Daudé

On 2/5/20 8:06 AM, pannengy...@huawei.com wrote:

From: Pan Nengyuan 

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

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

This patch delay timer_new to fix this memleaks.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Cc: Alistair Francis 
---
  hw/timer/stm32f2xx_timer.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index fb370ce0f0..06ec8a02c2 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
  memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
"stm32f2xx_timer", 0x400);
  sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
  
+static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)

+{
+STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
  s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
  }
  
@@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, void *data)

  dc->reset = stm32f2xx_timer_reset;
  device_class_set_props(dc, stm32f2xx_timer_properties);
  dc->vmsd = &vmstate_stm32f2xx_timer;
+dc->realize = stm32f2xx_timer_realize;
  }
  
  static const TypeInfo stm32f2xx_timer_info = {




Reviewed-by: Philippe Mathieu-Daudé 




[PATCH 2/3] stm32f2xx_timer: delay timer_new to avoid memleaks

2020-02-04 Thread pannengyuan
From: Pan Nengyuan 

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

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

This patch delay timer_new to fix this memleaks.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Cc: Alistair Francis 
---
 hw/timer/stm32f2xx_timer.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index fb370ce0f0..06ec8a02c2 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -314,7 +314,11 @@ static void stm32f2xx_timer_init(Object *obj)
 memory_region_init_io(&s->iomem, obj, &stm32f2xx_timer_ops, s,
   "stm32f2xx_timer", 0x400);
 sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
 
+static void stm32f2xx_timer_realize(DeviceState *dev, Error **errp)
+{
+STM32F2XXTimerState *s = STM32F2XXTIMER(dev);
 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, stm32f2xx_timer_interrupt, s);
 }
 
@@ -325,6 +329,7 @@ static void stm32f2xx_timer_class_init(ObjectClass *klass, 
void *data)
 dc->reset = stm32f2xx_timer_reset;
 device_class_set_props(dc, stm32f2xx_timer_properties);
 dc->vmsd = &vmstate_stm32f2xx_timer;
+dc->realize = stm32f2xx_timer_realize;
 }
 
 static const TypeInfo stm32f2xx_timer_info = {
-- 
2.21.0.windows.1