qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 7/8] lm32: do not leak memory on object_new/object_unref
Date: Tue, 1 Oct 2019 16:04:37 +0200	[thread overview]
Message-ID: <4d56a237-f90c-2cfd-656e-86abad0b9d0b@redhat.com> (raw)
In-Reply-To: <1569936988-635-8-git-send-email-pbonzini@redhat.com>

On 10/1/19 3:36 PM, Paolo Bonzini wrote:
> Bottom halves and ptimers are malloced, but nothing in these
> files is freeing memory allocated by instance_init.  Since
> these are sysctl devices that are never unrealized, just moving
> the allocations to realize is enough to avoid the leak in
> practice (and also to avoid upsetting asan when running
> device-introspect-test).
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/timer/lm32_timer.c       |  6 +++---
>   hw/timer/milkymist-sysctl.c | 10 +++++-----
>   2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
> index ac3edaf..cf316ed 100644
> --- a/hw/timer/lm32_timer.c
> +++ b/hw/timer/lm32_timer.c
> @@ -186,9 +186,6 @@ static void lm32_timer_init(Object *obj)
>   
>       sysbus_init_irq(dev, &s->irq);
>   
> -    s->bh = qemu_bh_new(timer_hit, s);
> -    s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
> -
>       memory_region_init_io(&s->iomem, obj, &timer_ops, s,
>                             "timer", R_MAX * 4);
>       sysbus_init_mmio(dev, &s->iomem);
> @@ -198,6 +195,9 @@ static void lm32_timer_realize(DeviceState *dev, Error **errp)
>   {
>       LM32TimerState *s = LM32_TIMER(dev);
>   
> +    s->bh = qemu_bh_new(timer_hit, s);
> +    s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
> +
>       ptimer_set_freq(s->ptimer, s->freq_hz);
>   }
>   
> diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
> index 9583507..6aedc11 100644
> --- a/hw/timer/milkymist-sysctl.c
> +++ b/hw/timer/milkymist-sysctl.c
> @@ -283,11 +283,6 @@ static void milkymist_sysctl_init(Object *obj)
>       sysbus_init_irq(dev, &s->timer0_irq);
>       sysbus_init_irq(dev, &s->timer1_irq);
>   
> -    s->bh0 = qemu_bh_new(timer0_hit, s);
> -    s->bh1 = qemu_bh_new(timer1_hit, s);
> -    s->ptimer0 = ptimer_init(s->bh0, PTIMER_POLICY_DEFAULT);
> -    s->ptimer1 = ptimer_init(s->bh1, PTIMER_POLICY_DEFAULT);
> -
>       memory_region_init_io(&s->regs_region, obj, &sysctl_mmio_ops, s,
>               "milkymist-sysctl", R_MAX * 4);
>       sysbus_init_mmio(dev, &s->regs_region);
> @@ -297,6 +292,11 @@ static void milkymist_sysctl_realize(DeviceState *dev, Error **errp)
>   {
>       MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev);
>   
> +    s->bh0 = qemu_bh_new(timer0_hit, s);
> +    s->bh1 = qemu_bh_new(timer1_hit, s);
> +    s->ptimer0 = ptimer_init(s->bh0, PTIMER_POLICY_DEFAULT);
> +    s->ptimer1 = ptimer_init(s->bh1, PTIMER_POLICY_DEFAULT);
> +
>       ptimer_set_freq(s->ptimer0, s->freq_hz);
>       ptimer_set_freq(s->ptimer1, s->freq_hz);
>   }
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


  reply	other threads:[~2019-10-01 14:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 13:36 [PATCH ci-fix 0/8] fix various memory leaks (but not all) Paolo Bonzini
2019-10-01 13:36 ` [PATCH 1/8] ide: fix leak from qemu_allocate_irqs Paolo Bonzini
2019-10-01 14:25   ` Thomas Huth
2019-10-01 15:28   ` Eric Blake
2019-10-01 15:58   ` Peter Maydell
2019-10-01 16:52     ` Paolo Bonzini
2019-10-01 13:36 ` [PATCH 2/8] microblaze: fix leak of fdevice tree blob Paolo Bonzini
2019-10-01 14:01   ` Philippe Mathieu-Daudé
2019-10-01 13:36 ` [PATCH 3/8] mcf5208: fix leak from qemu_allocate_irqs Paolo Bonzini
2019-10-01 14:28   ` Thomas Huth
2019-10-01 13:36 ` [PATCH 4/8] hppa: fix leak from g_strdup_printf Paolo Bonzini
2019-10-01 13:59   ` Philippe Mathieu-Daudé
2019-10-01 13:36 ` [PATCH 5/8] mips: fix memory leaks in board initialization Paolo Bonzini
2019-10-01 14:34   ` Thomas Huth
2019-10-01 13:36 ` [PATCH 6/8] cris: do not leak struct cris_disasm_data Paolo Bonzini
2019-10-01 13:36 ` [PATCH 7/8] lm32: do not leak memory on object_new/object_unref Paolo Bonzini
2019-10-01 14:04   ` Philippe Mathieu-Daudé [this message]
2019-10-01 13:36 ` [PATCH 8/8] docker: test-debug: disable LeakSanitizer Paolo Bonzini
2019-10-01 13:59   ` Philippe Mathieu-Daudé
2019-10-01 16:53     ` Paolo Bonzini
2019-10-01 19:28 ` [PATCH ci-fix 0/8] fix various memory leaks (but not all) no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d56a237-f90c-2cfd-656e-86abad0b9d0b@redhat.com \
    --to=philmd@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).