* [Qemu-devel] [PATCH] qapi: Fix memory leak
@ 2012-08-18 20:51 Stefan Weil
2012-08-18 21:01 ` Stefan Weil
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Stefan Weil @ 2012-08-18 20:51 UTC (permalink / raw)
To: Laszlo Ersek; +Cc: Stefan Weil, qemu-devel
valgrind report:
==24534== 232 bytes in 2 blocks are definitely lost in loss record 1,245 of 1,601
==24534== at 0x4824F20: malloc (vg_replace_malloc.c:236)
==24534== by 0x293C88: malloc_and_trace (vl.c:2281)
==24534== by 0x489AD99: ??? (in /lib/libglib-2.0.so.0.2400.1)
==24534== by 0x489B23B: g_malloc0 (in /lib/libglib-2.0.so.0.2400.1)
==24534== by 0x2B4EFC: opts_visitor_new (opts-visitor.c:376)
==24534== by 0x29DEA5: net_client_init (net.c:708)
==24534== by 0x29E6C7: net_init_client (net.c:966)
==24534== by 0x2C2179: qemu_opts_foreach (qemu-option.c:1114)
==24534== by 0x29E85B: net_init_clients (net.c:1008)
==24534== by 0x296F40: main (vl.c:3463)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
qapi/opts-visitor.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index a59d306..e048b6c 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -416,7 +416,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
g_hash_table_destroy(ov->unprocessed_opts);
}
g_free(ov->fake_id_opt);
- memset(ov, '\0', sizeof *ov);
+ g_free(ov);
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-18 20:51 [Qemu-devel] [PATCH] qapi: Fix memory leak Stefan Weil
@ 2012-08-18 21:01 ` Stefan Weil
2012-08-19 10:37 ` Peter Maydell
2012-08-18 21:06 ` Michael Tokarev
2012-08-19 10:12 ` Laszlo Ersek
2 siblings, 1 reply; 7+ messages in thread
From: Stefan Weil @ 2012-08-18 21:01 UTC (permalink / raw)
To: Paul Brook; +Cc: qemu-devel
Am 18.08.2012 22:51, schrieb Stefan Weil:
> valgrind report:
>
> ==24534== 232 bytes in 2 blocks are definitely lost in loss record 1,245 of 1,601
> ==24534== at 0x4824F20: malloc (vg_replace_malloc.c:236)
> ==24534== by 0x293C88: malloc_and_trace (vl.c:2281)
> ==24534== by 0x489AD99: ??? (in /lib/libglib-2.0.so.0.2400.1)
> ==24534== by 0x489B23B: g_malloc0 (in /lib/libglib-2.0.so.0.2400.1)
> ==24534== by 0x2B4EFC: opts_visitor_new (opts-visitor.c:376)
> ==24534== by 0x29DEA5: net_client_init (net.c:708)
> ==24534== by 0x29E6C7: net_init_client (net.c:966)
> ==24534== by 0x2C2179: qemu_opts_foreach (qemu-option.c:1114)
> ==24534== by 0x29E85B: net_init_clients (net.c:1008)
> ==24534== by 0x296F40: main (vl.c:3463)
>
valgrind reports a lot more memory leaks which are related to
function qemu_allocate_irqs. In many cases, its return value
should be free'd. g_malloc / g_free can be avoided by adding
a new function
void qemu_init_irqs(qemu_irq_handler handler, void *opaque,
qemu_irq *irqs, int n);
If this is ok, I'll send patches which add and use the new
function instead of qemu_allocate_irqs, too.
Regards,
Stefan Weil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-18 20:51 [Qemu-devel] [PATCH] qapi: Fix memory leak Stefan Weil
2012-08-18 21:01 ` Stefan Weil
@ 2012-08-18 21:06 ` Michael Tokarev
2012-08-19 10:15 ` Laszlo Ersek
2012-08-19 10:12 ` Laszlo Ersek
2 siblings, 1 reply; 7+ messages in thread
From: Michael Tokarev @ 2012-08-18 21:06 UTC (permalink / raw)
To: Stefan Weil; +Cc: Laszlo Ersek, qemu-devel
On 19.08.2012 00:51, Stefan Weil wrote:
> +++ b/qapi/opts-visitor.c
> @@ -416,7 +416,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
> g_hash_table_destroy(ov->unprocessed_opts);
> }
> g_free(ov->fake_id_opt);
> - memset(ov, '\0', sizeof *ov);
> + g_free(ov);
Shouldn't the function be named opts_visitor_free() or .._destroy()
in this case? Or should maybe the caller free "ov" instead of
this function? To me it looks like either both free+rename shoud
be made, or none.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-18 20:51 [Qemu-devel] [PATCH] qapi: Fix memory leak Stefan Weil
2012-08-18 21:01 ` Stefan Weil
2012-08-18 21:06 ` Michael Tokarev
@ 2012-08-19 10:12 ` Laszlo Ersek
2012-08-20 14:05 ` Luiz Capitulino
2 siblings, 1 reply; 7+ messages in thread
From: Laszlo Ersek @ 2012-08-19 10:12 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
On 08/18/12 22:51, Stefan Weil wrote:
> valgrind report:
>
> ==24534== 232 bytes in 2 blocks are definitely lost in loss record 1,245 of 1,601
> ==24534== at 0x4824F20: malloc (vg_replace_malloc.c:236)
> ==24534== by 0x293C88: malloc_and_trace (vl.c:2281)
> ==24534== by 0x489AD99: ??? (in /lib/libglib-2.0.so.0.2400.1)
> ==24534== by 0x489B23B: g_malloc0 (in /lib/libglib-2.0.so.0.2400.1)
> ==24534== by 0x2B4EFC: opts_visitor_new (opts-visitor.c:376)
> ==24534== by 0x29DEA5: net_client_init (net.c:708)
> ==24534== by 0x29E6C7: net_init_client (net.c:966)
> ==24534== by 0x2C2179: qemu_opts_foreach (qemu-option.c:1114)
> ==24534== by 0x29E85B: net_init_clients (net.c:1008)
> ==24534== by 0x296F40: main (vl.c:3463)
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> qapi/opts-visitor.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index a59d306..e048b6c 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -416,7 +416,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
> g_hash_table_destroy(ov->unprocessed_opts);
> }
> g_free(ov->fake_id_opt);
> - memset(ov, '\0', sizeof *ov);
> + g_free(ov);
> }
>
>
I don't remember why I thought the object would / should live on. I must
have implemented what I thought was safe / correct for the life-cycle,
except I got the life-cycle wrong. Face, meet palm.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks & sorry!
Laszlo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-18 21:06 ` Michael Tokarev
@ 2012-08-19 10:15 ` Laszlo Ersek
0 siblings, 0 replies; 7+ messages in thread
From: Laszlo Ersek @ 2012-08-19 10:15 UTC (permalink / raw)
To: Michael Tokarev; +Cc: Stefan Weil, qemu-devel
On 08/18/12 23:06, Michael Tokarev wrote:
> On 19.08.2012 00:51, Stefan Weil wrote:
>
>> +++ b/qapi/opts-visitor.c
>> @@ -416,7 +416,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
>
>> g_hash_table_destroy(ov->unprocessed_opts);
>> }
>> g_free(ov->fake_id_opt);
>> - memset(ov, '\0', sizeof *ov);
>> + g_free(ov);
>
> Shouldn't the function be named opts_visitor_free() or .._destroy()
> in this case? Or should maybe the caller free "ov" instead of
> this function? To me it looks like either both free+rename shoud
> be made, or none.
All of
- string-output-visitor.c
- string-input-visitor.c
- qmp-output-visitor.c
- qmp-input-visitor.c
- qapi-dealloc-visitor.c
free the visitor in *_cleanup(). (Which is not to say they shouldn't all
be renamed, only that the patch uni-forms opts-visitor with the rest.)
Thanks,
Laszlo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-18 21:01 ` Stefan Weil
@ 2012-08-19 10:37 ` Peter Maydell
0 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2012-08-19 10:37 UTC (permalink / raw)
To: Stefan Weil; +Cc: Anthony Liguori, Paul Brook, qemu-devel
On 18 August 2012 22:01, Stefan Weil <sw@weilnetz.de> wrote:
> valgrind reports a lot more memory leaks which are related to
> function qemu_allocate_irqs. In many cases, its return value
> should be free'd. g_malloc / g_free can be avoided by adding
> a new function
>
> void qemu_init_irqs(qemu_irq_handler handler, void *opaque,
> qemu_irq *irqs, int n);
>
> If this is ok, I'll send patches which add and use the new
> function instead of qemu_allocate_irqs, too.
So I think the long term plan is that these will basically go
away in favour of some kind of Pin based infrastructure.
Given that, it might not be worth doing unless these leaks
are more than "memory lasts for lifetime of qemu and we
don't free it explicitly" (maybe you could actual leaks in a
hotplug scenario?)
-- PMM
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] qapi: Fix memory leak
2012-08-19 10:12 ` Laszlo Ersek
@ 2012-08-20 14:05 ` Luiz Capitulino
0 siblings, 0 replies; 7+ messages in thread
From: Luiz Capitulino @ 2012-08-20 14:05 UTC (permalink / raw)
To: Laszlo Ersek; +Cc: Stefan Weil, qemu-devel
On Sun, 19 Aug 2012 12:12:29 +0200
Laszlo Ersek <lersek@redhat.com> wrote:
> On 08/18/12 22:51, Stefan Weil wrote:
> > valgrind report:
> >
> > ==24534== 232 bytes in 2 blocks are definitely lost in loss record 1,245 of 1,601
> > ==24534== at 0x4824F20: malloc (vg_replace_malloc.c:236)
> > ==24534== by 0x293C88: malloc_and_trace (vl.c:2281)
> > ==24534== by 0x489AD99: ??? (in /lib/libglib-2.0.so.0.2400.1)
> > ==24534== by 0x489B23B: g_malloc0 (in /lib/libglib-2.0.so.0.2400.1)
> > ==24534== by 0x2B4EFC: opts_visitor_new (opts-visitor.c:376)
> > ==24534== by 0x29DEA5: net_client_init (net.c:708)
> > ==24534== by 0x29E6C7: net_init_client (net.c:966)
> > ==24534== by 0x2C2179: qemu_opts_foreach (qemu-option.c:1114)
> > ==24534== by 0x29E85B: net_init_clients (net.c:1008)
> > ==24534== by 0x296F40: main (vl.c:3463)
> >
> > Signed-off-by: Stefan Weil <sw@weilnetz.de>
> > ---
> > qapi/opts-visitor.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> > index a59d306..e048b6c 100644
> > --- a/qapi/opts-visitor.c
> > +++ b/qapi/opts-visitor.c
> > @@ -416,7 +416,7 @@ opts_visitor_cleanup(OptsVisitor *ov)
> > g_hash_table_destroy(ov->unprocessed_opts);
> > }
> > g_free(ov->fake_id_opt);
> > - memset(ov, '\0', sizeof *ov);
> > + g_free(ov);
> > }
> >
> >
>
> I don't remember why I thought the object would / should live on. I must
> have implemented what I thought was safe / correct for the life-cycle,
> except I got the life-cycle wrong. Face, meet palm.
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Applied to the qmp branch for 1.2.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-08-20 14:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-18 20:51 [Qemu-devel] [PATCH] qapi: Fix memory leak Stefan Weil
2012-08-18 21:01 ` Stefan Weil
2012-08-19 10:37 ` Peter Maydell
2012-08-18 21:06 ` Michael Tokarev
2012-08-19 10:15 ` Laszlo Ersek
2012-08-19 10:12 ` Laszlo Ersek
2012-08-20 14:05 ` Luiz Capitulino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).