Re: [PATCH 3/3] stellaris: 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 = 
stellaris-gptm. It's easy to reproduce as follow:

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

This patch delay timer_new in realize to fix it.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Cc: qemu-...@nongnu.org
---
  hw/arm/stellaris.c | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index bb025e0bd0..221a78674e 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -347,11 +347,15 @@ static void stellaris_gptm_init(Object *obj)
  sysbus_init_mmio(sbd, &s->iomem);
  
  s->opaque[0] = s->opaque[1] = s;

+}
+
+static void stellaris_gptm_realize(DeviceState *dev, Error **errp)
+{
+gptm_state *s = STELLARIS_GPTM(dev);
  s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]);
  s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]);
  }
  
-

  /* System controller.  */
  
  typedef struct {

@@ -1536,6 +1540,7 @@ static void stellaris_gptm_class_init(ObjectClass *klass, 
void *data)
  DeviceClass *dc = DEVICE_CLASS(klass);
  
  dc->vmsd = &vmstate_stellaris_gptm;

+dc->realize = stellaris_gptm_realize;
  }
  
  static const TypeInfo stellaris_gptm_info = {




Reviewed-by: Philippe Mathieu-Daudé 




[PATCH 3/3] stellaris: 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 = 
stellaris-gptm. It's easy to reproduce as follow:

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

This patch delay timer_new in realize to fix it.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Cc: qemu-...@nongnu.org
---
 hw/arm/stellaris.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index bb025e0bd0..221a78674e 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -347,11 +347,15 @@ static void stellaris_gptm_init(Object *obj)
 sysbus_init_mmio(sbd, &s->iomem);
 
 s->opaque[0] = s->opaque[1] = s;
+}
+
+static void stellaris_gptm_realize(DeviceState *dev, Error **errp)
+{
+gptm_state *s = STELLARIS_GPTM(dev);
 s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]);
 s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]);
 }
 
-
 /* System controller.  */
 
 typedef struct {
@@ -1536,6 +1540,7 @@ static void stellaris_gptm_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc->vmsd = &vmstate_stellaris_gptm;
+dc->realize = stellaris_gptm_realize;
 }
 
 static const TypeInfo stellaris_gptm_info = {
-- 
2.21.0.windows.1