Skip to contentSkip to conversation

Fix some memleaks caused by ptimer_init

PATCH Superseded Gan Qixin 2 participants 13 messages Nov 27, 2020 – Dec 15, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gan Qixin

author
#0 lore raw

cover Fix some memleaks caused by ptimer_init

Hi all,

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

Gan Qixin (7):
allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid
memleaks
digic-timer: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_mct: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_pwm: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_rtc: Use ptimer_free() in the finalize function to avoid
memleaks
mss-timer: Use ptimer_free() in the finalize function to avoid
memleaks
musicpal: Use ptimer_free() in the finalize function to avoid memleaks

 hw/arm/musicpal.c            | 22 +++++++++++++++++-----
 hw/rtc/exynos4210_rtc.c      | 19 ++++++++++++++-----
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 hw/timer/digic-timer.c       | 18 +++++++++++++-----
 hw/timer/exynos4210_mct.c    | 24 +++++++++++++++++++-----
 hw/timer/exynos4210_pwm.c    | 21 ++++++++++++++++-----
 hw/timer/mss-timer.c         | 23 ++++++++++++++++++-----
 7 files changed, 113 insertions(+), 35 deletions(-)
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 1/7 allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

When running device-introspect-test, a memory leak occurred in the a10_pit_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 288 byte(s) in 6 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 0xaaabf555db84 in timer_new_full /qemu/include/qemu/timer.h:523
    #3 0xaaabf555db84 in timer_new /qemu/include/qemu/timer.h:544
    #4 0xaaabf555db84 in timer_new_ns /qemu/include/qemu/timer.h:562
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf57415e8 in a10_pit_init /qemu/hw/timer/allwinner-a10-pit.c:278
    #7 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #8 0xaaabf633ca04 in object_initialize_child_with_propsv /qemu/qom/object.c:564
    #9 0xaaabf633cc08 in object_initialize_child_with_props /qemu/qom/object.c:547
    #10 0xaaabf5b94680 in aw_a10_init /qemu/hw/arm/allwinner-a10.c:49
    #11 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #12 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729

---
Cc: Beniamino Galvani <[email protected]>

---
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/timer/allwinner-a10-pit.c +16 -5
index f84fc0ea25..be211983b0 100644
@@ -279,6 +279,16 @@ static void a10_pit_init(Object *obj)
     }
 }
 
+static void a10_pit_finalize(Object *obj)
+{
+    AwA10PITState *s = AW_A10_PIT(obj);
+    int i;
+
+    for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
+        ptimer_free(s->timer[i]);
+    }
+}
+
 static void a10_pit_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -290,11 +300,12 @@ static void a10_pit_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo a10_pit_info = {
-    .name = TYPE_AW_A10_PIT,
-    .parent = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(AwA10PITState),
-    .instance_init = a10_pit_init,
-    .class_init = a10_pit_class_init,
+    .name              = TYPE_AW_A10_PIT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(AwA10PITState),
+    .instance_init     = a10_pit_init,
+    .instance_finalize = a10_pit_finalize,
+    .class_init        = a10_pit_class_init,
 };
 
 static void a10_register_types(void)
Signature · 1 line
2.23.0
#2 lore raw

Re: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 56 lines · Gan Qixin

When running device-introspect-test, a memory leak occurred in the a10_pit_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 288 byte(s) in 6 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 0xaaabf555db84 in timer_new_full /qemu/include/qemu/timer.h:523
    #3 0xaaabf555db84 in timer_new /qemu/include/qemu/timer.h:544
    #4 0xaaabf555db84 in timer_new_ns /qemu/include/qemu/timer.h:562
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf57415e8 in a10_pit_init /qemu/hw/timer/allwinner-a10-pit.c:278
    #7 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #8 0xaaabf633ca04 in object_initialize_child_with_propsv /qemu/qom/object.c:564
    #9 0xaaabf633cc08 in object_initialize_child_with_props /qemu/qom/object.c:547
    #10 0xaaabf5b94680 in aw_a10_init /qemu/hw/arm/allwinner-a10.c:49
    #11 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #12 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729

---
Cc: Beniamino Galvani <[email protected]>

---
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/timer/allwinner-a10-pit.c +10 -2
index f84fc0ea25..be211983b0 100644
@@ -279,6 +279,16 @@ static void a10_pit_init(Object *obj)
     }
 }
 
+static void a10_pit_finalize(Object *obj)
+{
+    AwA10PITState *s = AW_A10_PIT(obj);
+    int i;
+
+    for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
+        ptimer_free(s->timer[i]);
+    }
+}
+
 static void a10_pit_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -290,11 +300,12 @@ static void a10_pit_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo a10_pit_info = {
-    .name = TYPE_AW_A10_PIT,
-    .parent = TYPE_SYS_BUS_DEVICE,

hw/timer/allwinner-a10-pit.c static void a10_pit_class_init(ObjectClass *klass, void *data) · line 309

Quoted 10 lines
hw/timer/allwinner-a10-pit.c +6 -3
-    .instance_size = sizeof(AwA10PITState),
-    .instance_init = a10_pit_init,
-    .class_init = a10_pit_class_init,
+    .name              = TYPE_AW_A10_PIT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(AwA10PITState),
+    .instance_init     = a10_pit_init,
+    .instance_finalize = a10_pit_finalize,
+    .class_init        = a10_pit_class_init,
 };

Please don't make unrelated whitespace changes like this in a patch. We don't line up the assignments in this sort of struct -- this is deliberate, so that if a new line is added whose field name happens to be longer than those used already, the patch does not have to touch all the lines in the struct to maintain the formatting. Instead you get a readable diff where only the new line changes, not all the others.

thanks
-- PMM

#3 lore raw

Re: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 69 lines · Peter Maydell
Quoted 56 lines · Gan Qixin

When running device-introspect-test, a memory leak occurred in the a10_pit_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 288 byte(s) in 6 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 0xaaabf555db84 in timer_new_full /qemu/include/qemu/timer.h:523
    #3 0xaaabf555db84 in timer_new /qemu/include/qemu/timer.h:544
    #4 0xaaabf555db84 in timer_new_ns /qemu/include/qemu/timer.h:562
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf57415e8 in a10_pit_init /qemu/hw/timer/allwinner-a10-pit.c:278
    #7 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #8 0xaaabf633ca04 in object_initialize_child_with_propsv /qemu/qom/object.c:564
    #9 0xaaabf633cc08 in object_initialize_child_with_props /qemu/qom/object.c:547
    #10 0xaaabf5b94680 in aw_a10_init /qemu/hw/arm/allwinner-a10.c:49
    #11 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #12 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729

---
Cc: Beniamino Galvani <[email protected]>

---
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/timer/allwinner-a10-pit.c +10 -2
index f84fc0ea25..be211983b0 100644
@@ -279,6 +279,16 @@ static void a10_pit_init(Object *obj)
     }
 }
 
+static void a10_pit_finalize(Object *obj)
+{
+    AwA10PITState *s = AW_A10_PIT(obj);
+    int i;
+
+    for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
+        ptimer_free(s->timer[i]);
+    }
+}
+
 static void a10_pit_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -290,11 +300,12 @@ static void a10_pit_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo a10_pit_info = {
-    .name = TYPE_AW_A10_PIT,
-    .parent = TYPE_SYS_BUS_DEVICE,

hw/timer/allwinner-a10-pit.c static void a10_pit_class_init(ObjectClass *klass, void *data) · line 309

Quoted 10 lines
hw/timer/allwinner-a10-pit.c +6 -3
-    .instance_size = sizeof(AwA10PITState),
-    .instance_init = a10_pit_init,
-    .class_init = a10_pit_class_init,
+    .name              = TYPE_AW_A10_PIT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(AwA10PITState),
+    .instance_init     = a10_pit_init,
+    .instance_finalize = a10_pit_finalize,
+    .class_init        = a10_pit_class_init,
 };
Quoted 7 lines

Please don't make unrelated whitespace changes like this in a patch. We don't line up the assignments in this sort of struct -- this is deliberate, so that if a new line is added whose field name happens to be longer than those used already, the patch does not have to touch all the lines in the struct to maintain the formatting. Instead you get a readable diff where only the new line changes, not all the others.

Hmm. Having said that I see that the other 6 devices touched by this series did use the line-up-the-assignments style. Anyway, the style this device was using is the right one.

thanks
-- PMM

author
#4 lore raw

RE: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 102 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Tuesday, December 15, 2020 12:20 AM
To: ganqixin <[email protected]>
Cc: qemu-arm <[email protected]>; QEMU Developers <[email protected]>; Chenqun (kuhn) <[email protected]>; Zhanghailiang <[email protected]>; Euler Robot <[email protected]>; Beniamino Galvani <[email protected]>
Subject: Re: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 5 lines · Peter Maydell
Quoted 3 lines · Gan Qixin

When running device-introspect-test, a memory leak occurred in the a10_pit_init function, so use ptimer_free() in the finalize function to

avoid it.

Quoted 5 lines
Quoted 5 lines

ASAN shows memory leak stack:

Indirect leak of 288 byte(s) in 6 object(s) allocated from:

    #0 0xffffab97e1f0 in __interceptor_calloc

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

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

/qemu/include/qemu/timer.h:523

Quoted 1 line
Quoted 1 line
    #3 0xaaabf555db84 in timer_new

/qemu/include/qemu/timer.h:544

Quoted 1 line
Quoted 1 line
    #4 0xaaabf555db84 in timer_new_ns

/qemu/include/qemu/timer.h:562

Quoted 2 lines
Quoted 2 lines
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf57415e8 in a10_pit_init

/qemu/hw/timer/allwinner-a10-pit.c:278

Quoted 1 line
Quoted 1 line
    #7 0xaaabf6339f6c in object_initialize_with_type

/qemu/qom/object.c:515

Quoted 1 line
Quoted 1 line
    #8 0xaaabf633ca04 in object_initialize_child_with_propsv

/qemu/qom/object.c:564

Quoted 1 line
Quoted 1 line
    #9 0xaaabf633cc08 in object_initialize_child_with_props

/qemu/qom/object.c:547

Quoted 1 line
Quoted 1 line
    #10 0xaaabf5b94680 in aw_a10_init

/qemu/hw/arm/allwinner-a10.c:49

Quoted 1 line
Quoted 1 line
    #11 0xaaabf6339f6c in object_initialize_with_type

/qemu/qom/object.c:515

Quoted 11 lines
Quoted 11 lines
    #12 0xaaabf633a1e0 in object_new_with_type

/qemu/qom/object.c:729

---
Cc: Beniamino Galvani <[email protected]>

---
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0 -0

b/hw/timer/allwinner-a10-pit.c index f84fc0ea25..be211983b0

100644

Quoted 6 lines
Quoted 6 lines
hw/timer/allwinner-a10-pit.c +0 -0
@@ -279,6 +279,16 @@ static void a10_pit_init(Object *obj)
     }
 }
 
Quoted 11 lines

hw/timer/allwinner-a10-pit.c static void a10_pit_init(Object *obj)

Quoted 11 lines
hw/timer/allwinner-a10-pit.c +9 -0
+static void a10_pit_finalize(Object *obj) {
+    AwA10PITState *s = AW_A10_PIT(obj);
+    int i;
+
+    for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
+        ptimer_free(s->timer[i]);
+    }
+}
+
 static void a10_pit_class_init(ObjectClass *klass, void *data)  {
     DeviceClass *dc = DEVICE_CLASS(klass); @@ -290,11 +300,12

@@

Quoted 16 lines
Quoted 5 lines
hw/timer/allwinner-a10-pit.c +0 -2
 static void a10_pit_class_init(ObjectClass *klass, void *data)  }
 
 static const TypeInfo a10_pit_info = {
-    .name = TYPE_AW_A10_PIT,
-    .parent = TYPE_SYS_BUS_DEVICE,

hw/timer/allwinner-a10-pit.c static void a10_pit_class_init(ObjectClass *klass, void *data) · line 309

Quoted 10 lines
hw/timer/allwinner-a10-pit.c +6 -3
-    .instance_size = sizeof(AwA10PITState),
-    .instance_init = a10_pit_init,
-    .class_init = a10_pit_class_init,
+    .name              = TYPE_AW_A10_PIT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(AwA10PITState),
+    .instance_init     = a10_pit_init,
+    .instance_finalize = a10_pit_finalize,
+    .class_init        = a10_pit_class_init,
 };
Quoted 7 lines

Please don't make unrelated whitespace changes like this in a patch. We don't line up the assignments in this sort of struct -- this is deliberate, so that if a new line is added whose field name happens to be longer than those used already, the patch does not have to touch all the lines in the struct to maintain the formatting. Instead you get a readable diff where only the new line changes, not all the others.

Quoted 3 lines

Hmm. Having said that I see that the other 6 devices touched by this series did use the line-up-the-assignments style.
Anyway, the style this device was using is the right one.

Thanks for your reply, I will resend this patch. By the way, do we need to keep the other 6 devices in the same style as this device?

Gan Qixin

#5 lore raw

Re: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 23 lines · ganqixin
Quoted 23 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Tuesday, December 15, 2020 12:20 AM
To: ganqixin <[email protected]>
Cc: qemu-arm <[email protected]>; QEMU Developers <[email protected]>; Chenqun (kuhn) <[email protected]>; Zhanghailiang <[email protected]>; Euler Robot <[email protected]>; Beniamino Galvani <[email protected]>
Subject: Re: [PATCH 1/7] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks

Quoted 7 lines · Peter Maydell

Please don't make unrelated whitespace changes like this in a patch. We don't line up the assignments in this sort of struct -- this is deliberate, so that if a new line is added whose field name happens to be longer than those used already, the patch does not have to touch all the lines in the struct to maintain the formatting. Instead you get a readable diff where only the new line changes, not all the others.

Quoted 6 lines
Quoted 3 lines

Hmm. Having said that I see that the other 6 devices touched by this series did use the line-up-the-assignments style.
Anyway, the style this device was using is the right one.

Thanks for your reply, I will resend this patch. By the way, do we need to keep the other 6 devices in the same style as this device?

My suggestion would be that for all these files you just add the one new line you need to add, and leave the existing lines in the struct the way they are now (regardless of which style the file is currently using).

thanks
-- PMM

author
#6 lore raw

PATCH 2/7 digic-timer: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the digic_timer_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 288 byte(s) in 3 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 0xaaabf555db78 in ptimer_init /qemu/hw/core/ptimer.c:432
    #3 0xaaabf5b04084 in digic_timer_init /qemu/hw/timer/digic-timer.c:142
    #4 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #5 0xaaabf633ca04 in object_initialize_child_with_propsv /qemu/qom/object.c:564
    #6 0xaaabf633cc08 in object_initialize_child_with_props /qemu/qom/object.c:547
    #7 0xaaabf5b40e84 in digic_init /qemu/hw/arm/digic.c:46
    #8 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #9 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #10 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #11 0xaaabf653d8ec in qmp_marshal_device_list_properties /qemu/qapi/qapi-commands-qdev.c:59
    #12 0xaaabf6587d08 in do_qmp_dispatch_bh /qemu/qapi/qmp-dispatch.c:110

---
Cc: Antony Pavlov <[email protected]>

---
 hw/timer/digic-timer.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
hw/timer/digic-timer.c +13 -5
index 32612228da..86075987fb 100644
@@ -154,6 +154,13 @@ static void digic_timer_init(Object *obj)
     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
 }
 
+static void digic_timer_finalize(Object *obj)
+{
+    DigicTimerState *s = DIGIC_TIMER(obj);
+
+    ptimer_free(s->ptimer);
+}
+
 static void digic_timer_class_init(ObjectClass *klass, void *class_data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -163,11 +170,12 @@ static void digic_timer_class_init(ObjectClass *klass, void *class_data)
 }
 
 static const TypeInfo digic_timer_info = {
-    .name = TYPE_DIGIC_TIMER,
-    .parent = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(DigicTimerState),
-    .instance_init = digic_timer_init,
-    .class_init = digic_timer_class_init,
+    .name              = TYPE_DIGIC_TIMER,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(DigicTimerState),
+    .instance_init     = digic_timer_init,
+    .instance_finalize = digic_timer_finalize,
+    .class_init        = digic_timer_class_init,
 };
 
 static void digic_timer_register_type(void)
Signature · 1 line
2.23.0
author
#7 lore raw

PATCH 3/7 exynos4210_mct: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the exynos4210_mct_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 96 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 0xaaabf555db78 in ptimer_init /qemu/hw/core/ptimer.c:432
    #3 0xaaabf56b01a0 in exynos4210_mct_init /qemu/hw/timer/exynos4210_mct.c:1505
    #4 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #5 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #6 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #7 0xaaabf653d8ec in qmp_marshal_device_list_properties /qemu/qapi/qapi-commands-qdev.c:59
    #8 0xaaabf6587d08 in do_qmp_dispatch_bh /qemu/qapi/qmp-dispatch.c:110
    #9 0xaaabf6552708 in aio_bh_call /qemu/util/async.c:136
    #10 0xaaabf6552708 in aio_bh_poll /qemu/util/async.c:164
    #11 0xaaabf655f19c in aio_dispatch /qemu/util/aio-posix.c:381
    #12 0xaaabf65523f4 in aio_ctx_dispatch /qemu/util/async.c:306

---
Cc: Igor Mitsyanko <[email protected]>

---
 hw/timer/exynos4210_mct.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
hw/timer/exynos4210_mct.c +19 -5
index 439053acd2..7172ec425d 100644
@@ -1530,6 +1530,19 @@ static void exynos4210_mct_init(Object *obj)
     sysbus_init_mmio(dev, &s->iomem);
 }
 
+static void exynos4210_mct_finalize(Object *obj)
+{
+    int i;
+    Exynos4210MCTState *s = EXYNOS4210_MCT(obj);
+
+    ptimer_free(s->g_timer.ptimer_frc);
+
+    for (i = 0; i < 2; i++) {
+        ptimer_free(s->l_timer[i].tick_timer.ptimer_tick);
+        ptimer_free(s->l_timer[i].ptimer_frc);
+    }
+}
+
 static void exynos4210_mct_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -1539,11 +1552,12 @@ static void exynos4210_mct_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo exynos4210_mct_info = {
-    .name          = TYPE_EXYNOS4210_MCT,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(Exynos4210MCTState),
-    .instance_init = exynos4210_mct_init,
-    .class_init    = exynos4210_mct_class_init,
+    .name              = TYPE_EXYNOS4210_MCT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(Exynos4210MCTState),
+    .instance_init     = exynos4210_mct_init,
+    .instance_finalize = exynos4210_mct_finalize,
+    .class_init        = exynos4210_mct_class_init,
 };
 
 static void exynos4210_mct_register_types(void)
Signature · 1 line
2.23.0
author
#8 lore raw

PATCH 4/7 exynos4210_pwm: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the exynos4210_pwm_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 240 byte(s) in 5 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 0xaaabf555db84 in timer_new_full /qemu/include/qemu/timer.h:523
    #3 0xaaabf555db84 in timer_new /qemu/include/qemu/timer.h:544
    #4 0xaaabf555db84 in timer_new_ns /qemu/include/qemu/timer.h:562
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf56a36cc in exynos4210_pwm_init /qemu/hw/timer/exynos4210_pwm.c:401
    #7 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #8 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #9 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #10 0xaaabf653d8ec in qmp_marshal_device_list_properties /qemu/qapi/qapi-commands-qdev.c:59
    #11 0xaaabf6587d08 in do_qmp_dispatch_bh /qemu/qapi/qmp-dispatch.c:110
    #12 0xaaabf6552708 in aio_bh_call /qemu/util/async.c:136

---
Cc: Igor Mitsyanko <[email protected]>

---
 hw/timer/exynos4210_pwm.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
hw/timer/exynos4210_pwm.c +16 -5
index de181428b4..4764164d5e 100644
@@ -410,6 +410,16 @@ static void exynos4210_pwm_init(Object *obj)
     sysbus_init_mmio(dev, &s->iomem);
 }
 
+static void exynos4210_pwm_finalize(Object *obj)
+{
+    Exynos4210PWMState *s = EXYNOS4210_PWM(obj);
+    int i;
+
+    for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) {
+        ptimer_free(s->timer[i].ptimer);
+    }
+}
+
 static void exynos4210_pwm_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -419,11 +429,12 @@ static void exynos4210_pwm_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo exynos4210_pwm_info = {
-    .name          = TYPE_EXYNOS4210_PWM,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(Exynos4210PWMState),
-    .instance_init = exynos4210_pwm_init,
-    .class_init    = exynos4210_pwm_class_init,
+    .name              = TYPE_EXYNOS4210_PWM,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(Exynos4210PWMState),
+    .instance_init     = exynos4210_pwm_init,
+    .instance_finalize = exynos4210_pwm_finalize,
+    .class_init        = exynos4210_pwm_class_init,
 };
 
 static void exynos4210_pwm_register_types(void)
Signature · 1 line
2.23.0
author
#9 lore raw

PATCH 5/7 exynos4210_rtc: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the exynos4210_rtc_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 96 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 0xaaabf555db78 in ptimer_init /qemu/hw/core/ptimer.c:432
    #3 0xaaabf57b3934 in exynos4210_rtc_init /qemu/hw/rtc/exynos4210_rtc.c:567
    #4 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #5 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #6 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #7 0xaaabf653d8ec in qmp_marshal_device_list_properties /qemu/qapi/qapi-commands-qdev.c:59
    #8 0xaaabf6587d08 in do_qmp_dispatch_bh /qemu/qapi/qmp-dispatch.c:110
    #9 0xaaabf6552708 in aio_bh_call /qemu/util/async.c:136
    #10 0xaaabf6552708 in aio_bh_poll /qemu/util/async.c:164
    #11 0xaaabf655f19c in aio_dispatch /qemu/util/aio-posix.c:381
    #12 0xaaabf65523f4 in aio_ctx_dispatch /qemu/util/async.c:306

---
Cc: Igor Mitsyanko <[email protected]>

---
 hw/rtc/exynos4210_rtc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
hw/rtc/exynos4210_rtc.c +14 -5
index 4c97624478..2f667fb010 100644
@@ -584,6 +584,14 @@ static void exynos4210_rtc_init(Object *obj)
     sysbus_init_mmio(dev, &s->iomem);
 }
 
+static void exynos4210_rtc_finalize(Object *obj)
+{
+    Exynos4210RTCState *s = EXYNOS4210_RTC(obj);
+
+    ptimer_free(s->ptimer);
+    ptimer_free(s->ptimer_1Hz);
+}
+
 static void exynos4210_rtc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -593,11 +601,12 @@ static void exynos4210_rtc_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo exynos4210_rtc_info = {
-    .name          = TYPE_EXYNOS4210_RTC,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(Exynos4210RTCState),
-    .instance_init = exynos4210_rtc_init,
-    .class_init    = exynos4210_rtc_class_init,
+    .name              = TYPE_EXYNOS4210_RTC,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(Exynos4210RTCState),
+    .instance_init     = exynos4210_rtc_init,
+    .instance_finalize = exynos4210_rtc_finalize,
+    .class_init        = exynos4210_rtc_class_init,
 };
 
 static void exynos4210_rtc_register_types(void)
Signature · 1 line
2.23.0
author
#10 lore raw

PATCH 6/7 mss-timer: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the mss_timer_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 192 byte(s) in 2 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 0xaaabf555db78 in ptimer_init /qemu/hw/core/ptimer.c:432
    #3 0xaaabf58a0010 in mss_timer_init /qemu/hw/timer/mss-timer.c:235
    #4 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #5 0xaaabf633ca04 in object_initialize_child_with_propsv /qemu/qom/object.c:564
    #6 0xaaabf633cc08 in object_initialize_child_with_props /qemu/qom/object.c:547
    #7 0xaaabf5b8316c in m2sxxx_soc_initfn /qemu/hw/arm/msf2-soc.c:70
    #8 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #9 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #10 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #11 0xaaabf653d8ec in qmp_marshal_device_list_properties /qemu/qapi/qapi-commands-qdev.c:59
    #12 0xaaabf6587d08 in do_qmp_dispatch_bh /qemu/qapi/qmp-dispatch.c:110

---
Cc: Subbaraya Sundeep <[email protected]>

---
 hw/timer/mss-timer.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
hw/timer/mss-timer.c +18 -5
index 29943fd744..7c4f3a52da 100644
@@ -244,6 +244,18 @@ static void mss_timer_init(Object *obj)
     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &t->mmio);
 }
 
+static void mss_timer_finalize(Object *obj)
+{
+    MSSTimerState *t = MSS_TIMER(obj);
+    int i;
+
+    for (i = 0; i < NUM_TIMERS; i++) {
+        struct Msf2Timer *st = &t->timers[i];
+
+        ptimer_free(st->ptimer);
+    }
+}
+
 static const VMStateDescription vmstate_timers = {
     .name = "mss-timer-block",
     .version_id = 1,
@@ -283,11 +295,12 @@ static void mss_timer_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo mss_timer_info = {
-    .name          = TYPE_MSS_TIMER,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(MSSTimerState),
-    .instance_init = mss_timer_init,
-    .class_init    = mss_timer_class_init,
+    .name              = TYPE_MSS_TIMER,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(MSSTimerState),
+    .instance_init     = mss_timer_init,
+    .instance_finalize = mss_timer_finalize,
+    .class_init        = mss_timer_class_init,
 };
 
 static void mss_timer_register_types(void)
Signature · 1 line
2.23.0
author
#11 lore raw

PATCH 7/7 musicpal: Use ptimer_free() in the finalize function to avoid memleaks

In reply to Gan Qixin

When running device-introspect-test, a memory leak occurred in the mv88w8618_pit_init function, so use ptimer_free() in the finalize function to avoid it.

ASAN shows memory leak stack:

Indirect leak of 192 byte(s) in 4 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 0xaaabf555db84 in timer_new_full /qemu/include/qemu/timer.h:523
    #3 0xaaabf555db84 in timer_new /qemu/include/qemu/timer.h:544
    #4 0xaaabf555db84 in timer_new_ns /qemu/include/qemu/timer.h:562
    #5 0xaaabf555db84 in ptimer_init /qemu/hw/core/ptimer.c:433
    #6 0xaaabf5bb2290 in mv88w8618_timer_init /qemu/hw/arm/musicpal.c:862
    #7 0xaaabf5bb2290 in mv88w8618_pit_init /qemu/hw/arm/musicpal.c:954
    #8 0xaaabf6339f6c in object_initialize_with_type /qemu/qom/object.c:515
    #9 0xaaabf633a1e0 in object_new_with_type /qemu/qom/object.c:729
    #10 0xaaabf6375e40 in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:153
    #11 0xaaabf5a95540 in qdev_device_help /qemu/softmmu/qdev-monitor.c:283
    #12 0xaaabf5a96940 in qmp_device_add /qemu/softmmu/qdev-monitor.c:801

---
Cc: Jan Kiszka <[email protected]>

---
 hw/arm/musicpal.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
hw/arm/musicpal.c +17 -5
index 458b1cbeb7..0e77082e52 100644
@@ -959,6 +959,17 @@ static void mv88w8618_pit_init(Object *obj)
     sysbus_init_mmio(dev, &s->iomem);
 }
 
+static void mv88w8618_pit_finalize(Object *obj)
+{
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
+    mv88w8618_pit_state *s = MV88W8618_PIT(dev);
+    int i;
+
+    for (i = 0; i < 4; i++) {
+        ptimer_free(s->timer[i].ptimer);
+    }
+}
+
 static const VMStateDescription mv88w8618_timer_vmsd = {
     .name = "timer",
     .version_id = 1,
@@ -990,11 +1001,12 @@ static void mv88w8618_pit_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo mv88w8618_pit_info = {
-    .name          = TYPE_MV88W8618_PIT,
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(mv88w8618_pit_state),
-    .instance_init = mv88w8618_pit_init,
-    .class_init    = mv88w8618_pit_class_init,
+    .name              = TYPE_MV88W8618_PIT,
+    .parent            = TYPE_SYS_BUS_DEVICE,
+    .instance_size     = sizeof(mv88w8618_pit_state),
+    .instance_init     = mv88w8618_pit_init,
+    .instance_finalize = mv88w8618_pit_finalize,
+    .class_init        = mv88w8618_pit_class_init,
 };
 
 /* Flash config register offsets */
Signature · 1 line
2.23.0
author
#12 lore raw
In reply to Gan Qixin

Kindly ping!

Hi all,
These patches are waiting for review. Could someone help me check them?

Thanks,
Gan Qixin

Quoted 41 lines

-----Original Message-----
From: ganqixin
Sent: Friday, November 27, 2020 3:18 PM
To: [email protected]; [email protected]
Cc: [email protected]; Chenqun (kuhn) <[email protected]>; Zhanghailiang <[email protected]>; ganqixin <[email protected]>
Subject: [PATCH 0/7] Fix some memleaks caused by ptimer_init

Hi all,

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

Gan Qixin (7):
allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid
memleaks
digic-timer: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_mct: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_pwm: Use ptimer_free() in the finalize function to avoid
memleaks
exynos4210_rtc: Use ptimer_free() in the finalize function to avoid
memleaks
mss-timer: Use ptimer_free() in the finalize function to avoid
memleaks
musicpal: Use ptimer_free() in the finalize function to avoid memleaks

 hw/arm/musicpal.c            | 22 +++++++++++++++++-----
 hw/rtc/exynos4210_rtc.c      | 19 ++++++++++++++-----
 hw/timer/allwinner-a10-pit.c | 21 ++++++++++++++++-----
 hw/timer/digic-timer.c       | 18 +++++++++++++-----
 hw/timer/exynos4210_mct.c    | 24 +++++++++++++++++++-----
 hw/timer/exynos4210_pwm.c    | 21 ++++++++++++++++-----
 hw/timer/mss-timer.c         | 23 ++++++++++++++++++-----
 7 files changed, 113 insertions(+), 35 deletions(-)

--
2.23.0