qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak


From: gaosong
Subject: Re: [PATCH 2/2] hw/intc/loongson_ipi: Fix resource leak
Date: Tue, 23 Jul 2024 20:00:25 +0800
User-agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

在 2024/7/23 下午7:14, Philippe Mathieu-Daudé 写道:
Once initialised, QOM objects can be realized and
unrealized multiple times before being finalized.
Resources allocated in REALIZE must be deallocated
in an equivalent UNREALIZE handler.

Free the CPU array in loongson_ipi_unrealize()
instead of loongson_ipi_finalize().

Cc: qemu-stable@nongnu.org
Fixes: 5e90b8db382 ("hw/loongarch: Set iocsr address space per-board rather than 
percpu")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
  hw/intc/loongson_ipi.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
index e7979dbdd8b..4013f81745e 100644
--- a/hw/intc/loongson_ipi.c
+++ b/hw/intc/loongson_ipi.c
@@ -318,6 +318,13 @@ static void loongson_ipi_realize(DeviceState *dev, Error 
**errp)
      }
  }
+static void loongson_ipi_unrealize(DeviceState *dev)
+{
+    LoongsonIPI *s = LOONGSON_IPI(dev);
+
+    g_free(s->cpu);
+}
+
  static const VMStateDescription vmstate_ipi_core = {
      .name = "ipi-single",
      .version_id = 2,
@@ -353,23 +360,16 @@ static void loongson_ipi_class_init(ObjectClass *klass, 
void *data)
      DeviceClass *dc = DEVICE_CLASS(klass);
dc->realize = loongson_ipi_realize;
+    dc->unrealize = loongson_ipi_unrealize;
      device_class_set_props(dc, ipi_properties);
      dc->vmsd = &vmstate_loongson_ipi;
  }
-static void loongson_ipi_finalize(Object *obj)
-{
-    LoongsonIPI *s = LOONGSON_IPI(obj);
-
-    g_free(s->cpu);
-}
-
  static const TypeInfo loongson_ipi_info = {
      .name          = TYPE_LOONGSON_IPI,
      .parent        = TYPE_SYS_BUS_DEVICE,
      .instance_size = sizeof(LoongsonIPI),
      .class_init    = loongson_ipi_class_init,
-    .instance_finalize = loongson_ipi_finalize,
  };
static void loongson_ipi_register_types(void)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]