Skip to contentSkip to conversation

Fix some memleaks caused by timer_new_ns

PATCH Applied Gan Qixin 5 participants 10 messages Dec 4, 2020 – Dec 15, 2020

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Gan Qixin

author
#0 lore raw

cover Fix some memleaks caused by timer_new_ns

Hi all,

When running device-introspect-test, I found some memory leaks caused by timer_new_ns in the init function, so I free it in the finalize function.

Gan Qixin (3):
pl031: Use timer_free() in the finalize function to avoid memleaks misc/mos6522: Use timer_free() in the finalize function to avoid
memleak
s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

 hw/misc/mos6522.c  | 11 +++++++++++
 hw/rtc/pl031.c     | 19 ++++++++++++++-----
 target/s390x/cpu.c |  5 +++++
 3 files changed, 30 insertions(+), 5 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/3 pl031: Use timer_free() in the finalize function to avoid memleaks

When running device-introspect-test, a memory leak occurred in the pl031_init function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 48 byte(s) in 1 object(s) allocated from:

    #0 0xffffab97e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xffffab256800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaabf5621cfc in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaabf5621cfc in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaabf5621cfc in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaabf5621cfc in pl031_init qemu/hw/rtc/pl031.c:194
    #6 0xaaabf6339f6c in object_initialize_with_type qemu/qom/object.c:515
    #7 0xaaabf633a1e0 in object_new_with_type qemu/qom/object.c:729
    #8 0xaaabf6375e40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #9 0xaaabf5a95540 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #10 0xaaabf5a96940 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #11 0xaaabf5a96e70 in hmp_device_add qemu/softmmu/qdev-monitor.c:916
    #12 0xaaabf5ac0a2c in handle_hmp_command qemu/monitor/hmp.c:1100

---
Cc: Peter Maydell <[email protected]>

---
 hw/rtc/pl031.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/rtc/pl031.c +14 -5
index ae47f09635..2ea3dc1281 100644
@@ -194,6 +194,14 @@ static void pl031_init(Object *obj)
     s->timer = timer_new_ns(rtc_clock, pl031_interrupt, s);
 }
 
+static void pl031_finalize(Object *obj)
+{
+    PL031State *s = PL031(obj);
+
+    timer_del(s->timer);
+    timer_free(s->timer);
+}
+
 static int pl031_pre_save(void *opaque)
 {
     PL031State *s = opaque;
@@ -325,11 +333,12 @@ static void pl031_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo pl031_info = {
-    .name          = TYPE_PL031,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(PL031State),
-    .instance_init = pl031_init,
-    .class_init    = pl031_class_init,
+    .name              = TYPE_PL031,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(PL031State),
+    .instance_init     = pl031_init,
+    .instance_finalize = pl031_finalize,
+    .class_init        = pl031_class_init,
 };
 
 static void pl031_register_types(void)
Signature · 1 line
2.27.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] pl031: Use timer_free() in the finalize function to avoid memleaks

Quoted 21 lines · Gan Qixin

When running device-introspect-test, a memory leak occurred in the pl031_init function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 48 byte(s) in 1 object(s) allocated from:

    #0 0xffffab97e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xffffab256800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaabf5621cfc in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaabf5621cfc in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaabf5621cfc in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaabf5621cfc in pl031_init qemu/hw/rtc/pl031.c:194
    #6 0xaaabf6339f6c in object_initialize_with_type qemu/qom/object.c:515
    #7 0xaaabf633a1e0 in object_new_with_type qemu/qom/object.c:729
    #8 0xaaabf6375e40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #9 0xaaabf5a95540 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #10 0xaaabf5a96940 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #11 0xaaabf5a96e70 in hmp_device_add qemu/softmmu/qdev-monitor.c:916
    #12 0xaaabf5ac0a2c in handle_hmp_command qemu/monitor/hmp.c:1100
Quoted 4 lines

---
Cc: Peter Maydell <[email protected]>

thanks
-- PMM

author
#3 lore raw

PATCH 2/3 misc/mos6522: Use timer_free() in the finalize function to avoid memleak

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the mos6522_init function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 96 byte(s) in 2 object(s) allocated from:

    #0 0xfffd5fe9e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffd5f7b6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaae50303d0c in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaae50303d0c in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaae50303d0c in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaae50303d0c in mos6522_init qemu/hw/misc/mos6522.c:490
    #6 0xaaae50b77d70 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaae50b7ae84 in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaae50b7b0f8 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaae50bb6d58 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaae50d7e1dc in qmp_marshal_device_list_properties qemu/qapi/qapi-commands-qdev.c:59
    #11 0xaaae50dc87a0 in do_qmp_dispatch_bh qemu/qapi/qmp-dispatch.c:110
    #12 0xaaae50d931a0 in aio_bh_call qemu/util/async.c:136

---
Cc: David Gibson <[email protected]>

---
 hw/misc/mos6522.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/misc/mos6522.c +11 -0
index ac4cd1d58e..0236eeece1 100644
@@ -490,6 +490,16 @@ static void mos6522_init(Object *obj)
     s->timers[1].timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, mos6522_timer2, s);
 }
 
+static void mos6522_finalize(Object *obj)
+{
+    MOS6522State *s = MOS6522(obj);
+
+    timer_del(s->timers[0].timer);
+    timer_free(s->timers[0].timer);
+    timer_del(s->timers[1].timer);
+    timer_free(s->timers[1].timer);
+}
+
 static Property mos6522_properties[] = {
     DEFINE_PROP_UINT64("frequency", MOS6522State, frequency, 0),
     DEFINE_PROP_END_OF_LIST()
@@ -519,6 +529,7 @@ static const TypeInfo mos6522_type_info = {
     .parent = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(MOS6522State),
     .instance_init = mos6522_init,
+    .instance_finalize = mos6522_finalize,
     .abstract = true,
     .class_size = sizeof(MOS6522DeviceClass),
     .class_init = mos6522_class_init,
Signature · 1 line
2.27.0
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] misc/mos6522: Use timer_free() in the finalize function to avoid memleak

Quoted 20 lines · Gan Qixin

When running device-introspect-test, a memory leak occurred in the mos6522_init function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 96 byte(s) in 2 object(s) allocated from:

    #0 0xfffd5fe9e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffd5f7b6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaae50303d0c in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaae50303d0c in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaae50303d0c in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaae50303d0c in mos6522_init qemu/hw/misc/mos6522.c:490
    #6 0xaaae50b77d70 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaae50b7ae84 in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaae50b7b0f8 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaae50bb6d58 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaae50d7e1dc in qmp_marshal_device_list_properties qemu/qapi/qapi-commands-qdev.c:59
    #11 0xaaae50dc87a0 in do_qmp_dispatch_bh qemu/qapi/qmp-dispatch.c:110
    #12 0xaaae50d931a0 in aio_bh_call qemu/util/async.c:136
Quoted 2 lines
Quoted 35 lines

---
Cc: David Gibson <[email protected]>

---
 hw/misc/mos6522.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/misc/mos6522.c +11 -0
index ac4cd1d58e..0236eeece1 100644
@@ -490,6 +490,16 @@ static void mos6522_init(Object *obj)
     s->timers[1].timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, mos6522_timer2, s);
 }
 
+static void mos6522_finalize(Object *obj)
+{
+    MOS6522State *s = MOS6522(obj);
+
+    timer_del(s->timers[0].timer);
+    timer_free(s->timers[0].timer);
+    timer_del(s->timers[1].timer);
+    timer_free(s->timers[1].timer);
+}
+
 static Property mos6522_properties[] = {
     DEFINE_PROP_UINT64("frequency", MOS6522State, frequency, 0),
     DEFINE_PROP_END_OF_LIST()
@@ -519,6 +529,7 @@ static const TypeInfo mos6522_type_info = {
     .parent = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(MOS6522State),
     .instance_init = mos6522_init,
+    .instance_finalize = mos6522_finalize,
     .abstract = true,
     .class_size = sizeof(MOS6522DeviceClass),
     .class_init = mos6522_class_init,
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#5 lore raw

PATCH 3/3 s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 3552 byte(s) in 74 object(s) allocated from:

    #0 0xfffeb3d4e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaad51a8f9c4 in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaad51a8f9c4 in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaad51a8f9c4 in s390_cpu_initfn qemu/target/s390x/cpu.c:304
    #6 0xaaad51e00f58 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaad51e0406c in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaad51e042e0 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaad51e3ff40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaad51910518 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #11 0xaaad51911918 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #12 0xaaad51911e48 in hmp_device_add qemu/softmmu/qdev-monitor.c:916

---
Cc: Thomas Huth <[email protected]>

---
 target/s390x/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
target/s390x/cpu.c +5 -0
index 7b66718c44..8a734c2f8c 100644
@@ -313,6 +313,11 @@ static void s390_cpu_finalize(Object *obj)
 #if !defined(CONFIG_USER_ONLY)
     S390CPU *cpu = S390_CPU(obj);
 
+    timer_del(cpu->env.tod_timer);
+    timer_free(cpu->env.tod_timer);
+    timer_del(cpu->env.cpu_timer);
+    timer_free(cpu->env.cpu_timer);
+
     qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
     g_free(cpu->irqstate);
 #endif
Signature · 1 line
2.27.0
#6 lore raw

Re: [PATCH 3/3] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

Quoted 20 lines · On Fri, 4 Dec 2020 16:12:09 +0800 Gan Qixin <[email protected]> wrote:

When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 3552 byte(s) in 74 object(s) allocated from:

    #0 0xfffeb3d4e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaad51a8f9c4 in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaad51a8f9c4 in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaad51a8f9c4 in s390_cpu_initfn qemu/target/s390x/cpu.c:304
    #6 0xaaad51e00f58 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaad51e0406c in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaad51e042e0 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaad51e3ff40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaad51910518 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #11 0xaaad51911918 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #12 0xaaad51911e48 in hmp_device_add qemu/softmmu/qdev-monitor.c:916
Quoted 4 lines

---
Cc: Thomas Huth <[email protected]>

[Adding missing maintainers. How did you build the cc: list?]

Quoted 10 lines
---
 target/s390x/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
target/s390x/cpu.c +0 -0
index 7b66718c44..8a734c2f8c 100644
@@ -313,6 +313,11 @@ static void s390_cpu_finalize(Object *obj)
 #if !defined(CONFIG_USER_ONLY)

target/s390x/cpu.c static void s390_cpu_finalize(Object *obj) · line 323

Quoted 10 lines
target/s390x/cpu.c +5 -0
     S390CPU *cpu = S390_CPU(obj);
 
+    timer_del(cpu->env.tod_timer);
+    timer_free(cpu->env.tod_timer);
+    timer_del(cpu->env.cpu_timer);
+    timer_free(cpu->env.cpu_timer);
+
     qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
     g_free(cpu->irqstate);
 #endif

Looks sane at first glance.

Reviewed-by
#7 lore raw

Re: [PATCH 3/3] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

Quoted 42 lines · Cornelia Huck
Quoted 20 lines · On Fri, 4 Dec 2020 16:12:09 +0800 Gan Qixin <[email protected]> wrote:

When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 3552 byte(s) in 74 object(s) allocated from:

    #0 0xfffeb3d4e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaad51a8f9c4 in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaad51a8f9c4 in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaad51a8f9c4 in s390_cpu_initfn qemu/target/s390x/cpu.c:304
    #6 0xaaad51e00f58 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaad51e0406c in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaad51e042e0 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaad51e3ff40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaad51910518 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #11 0xaaad51911918 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #12 0xaaad51911e48 in hmp_device_add qemu/softmmu/qdev-monitor.c:916
Quoted 4 lines

---
Cc: Thomas Huth <[email protected]>

[Adding missing maintainers. How did you build the cc: list?]

Quoted 12 lines
---
 target/s390x/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
target/s390x/cpu.c +0 -0
index 7b66718c44..8a734c2f8c 100644
@@ -313,6 +313,11 @@ static void s390_cpu_finalize(Object *obj)
 #if !defined(CONFIG_USER_ONLY)
     S390CPU *cpu = S390_CPU(obj);
 
Quoted 11 lines

target/s390x/cpu.c static void s390_cpu_finalize(Object *obj) · line 323

Quoted 8 lines
target/s390x/cpu.c +5 -0
+    timer_del(cpu->env.tod_timer);
+    timer_free(cpu->env.tod_timer);
+    timer_del(cpu->env.cpu_timer);
+    timer_free(cpu->env.cpu_timer);
+
     qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
     g_free(cpu->irqstate);
 #endif

Looks sane at first glance.

Could have sworn we had these in the code at one point - but I don't find anything in the git history.

Signature · 3 lines
Thanks,

David / dhildenb
author
#8 lore raw

RE: [PATCH 3/3] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

In reply to Cornelia Huck
Quoted 49 lines

-----Original Message-----
From: Cornelia Huck [mailto:[email protected]]
Sent: Friday, December 4, 2020 4:37 PM
To: ganqixin <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Zhanghailiang <[email protected]>; Euler Robot <[email protected]>; Chenqun (kuhn) <[email protected]>; [email protected]; Richard Henderson <[email protected]>; David Hildenbrand <[email protected]>; [email protected]
Subject: Re: [PATCH 3/3] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

Quoted 2 lines · On Fri, 4 Dec 2020 16:12:09 +0800 Gan Qixin <[email protected]> wrote:

When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize

function to fix it.

Quoted 5 lines

ASAN shows memory leak stack:

Direct leak of 3552 byte(s) in 74 object(s) allocated from:

    #0 0xfffeb3d4e1f0 in __interceptor_calloc

(/lib64/libasan.so.5+0xee1f0)

Quoted 2 lines
    #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaad51a8f9c4 in timer_new_full

qemu/include/qemu/timer.h:523

Quoted 2 lines
    #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaad51a8f9c4 in timer_new_ns

qemu/include/qemu/timer.h:562

Quoted 1 line
    #5 0xaaad51a8f9c4 in s390_cpu_initfn

qemu/target/s390x/cpu.c:304

Quoted 1 line
    #6 0xaaad51e00f58 in object_init_with_type

qemu/qom/object.c:371

Quoted 1 line
    #7 0xaaad51e0406c in object_initialize_with_type

qemu/qom/object.c:515

Quoted 1 line
    #8 0xaaad51e042e0 in object_new_with_type

qemu/qom/object.c:729

Quoted 1 line
    #9 0xaaad51e3ff40 in qmp_device_list_properties

qemu/qom/qom-qmp-cmds.c:153

Quoted 1 line
    #10 0xaaad51910518 in qdev_device_help

qemu/softmmu/qdev-monitor.c:283

Quoted 1 line
    #11 0xaaad51911918 in qmp_device_add

qemu/softmmu/qdev-monitor.c:801

Quoted 3 lines
    #12 0xaaad51911e48 in hmp_device_add

qemu/softmmu/qdev-monitor.c:916

Quoted 6 lines
Quoted 4 lines

---
Cc: Thomas Huth <[email protected]>

[Adding missing maintainers. How did you build the cc: list?]

Oops, It's my fault. Thanks for helping me add missing maintainers. :)

Gan Qixin

Quoted 23 lines
Quoted 11 lines
---
 target/s390x/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
target/s390x/cpu.c index renamed from target/s390x/cpu.c +0 -0

7b66718c44..8a734c2f8c 100644

target/s390x/cpu.c +0 -0
@@ -313,6 +313,11 @@ static void s390_cpu_finalize(Object *obj)  #if
 !defined(CONFIG_USER_ONLY)

target/s390x/cpu.c static void s390_cpu_finalize(Object *obj) #if · line 323

Quoted 10 lines
target/s390x/cpu.c +5 -0
     S390CPU *cpu = S390_CPU(obj);
 
+    timer_del(cpu->env.tod_timer);
+    timer_free(cpu->env.tod_timer);
+    timer_del(cpu->env.cpu_timer);
+    timer_free(cpu->env.cpu_timer);
+
     qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
     g_free(cpu->irqstate);
 #endif

Looks sane at first glance.

#9 lore raw

Re: [PATCH 3/3] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin
Quoted 20 lines · On Fri, 4 Dec 2020 16:12:09 +0800 Gan Qixin <[email protected]> wrote:

When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize function to fix it.

ASAN shows memory leak stack:

Direct leak of 3552 byte(s) in 74 object(s) allocated from:

    #0 0xfffeb3d4e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0)
    #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800)
    #2 0xaaad51a8f9c4 in timer_new_full qemu/include/qemu/timer.h:523
    #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544
    #4 0xaaad51a8f9c4 in timer_new_ns qemu/include/qemu/timer.h:562
    #5 0xaaad51a8f9c4 in s390_cpu_initfn qemu/target/s390x/cpu.c:304
    #6 0xaaad51e00f58 in object_init_with_type qemu/qom/object.c:371
    #7 0xaaad51e0406c in object_initialize_with_type qemu/qom/object.c:515
    #8 0xaaad51e042e0 in object_new_with_type qemu/qom/object.c:729
    #9 0xaaad51e3ff40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaad51910518 in qdev_device_help qemu/softmmu/qdev-monitor.c:283
    #11 0xaaad51911918 in qmp_device_add qemu/softmmu/qdev-monitor.c:801
    #12 0xaaad51911e48 in hmp_device_add qemu/softmmu/qdev-monitor.c:916
Quoted 7 lines

---
Cc: Thomas Huth <[email protected]>

---
 target/s390x/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)

Thanks, applied.