qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Pan Nengyuan <pannengyuan@huawei.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Corey Minyard <minyard@acm.org>
Subject: Re: [PATCH 2/2] hw/sd/sd: Delay timer_new_ns() from init to realize to avoid memleaks
Date: Fri, 5 Jun 2020 07:05:52 +0200	[thread overview]
Message-ID: <a36cb24a-0d0d-7772-b30e-81df474462cd@redhat.com> (raw)
In-Reply-To: <CAFEAcA8P9yFjX5t96NJwzQpFEwsYg1eAWicO-Vneh1_zszJ_Aw@mail.gmail.com>

On 2/17/20 2:26 PM, Peter Maydell wrote:
> On Sat, 15 Feb 2020 at 15:48, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> In commit f3a508eb4e the Euler Robot reported calling timer_new()
>> in instance_init() can leak heap memory. The easier fix is to
>> delay the timer creation at instance realize(). Similarly move
>> timer_del() into a new instance unrealize() method.
> 
>> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
>> index 71a9af09ab..d72cf3de2a 100644
>> --- a/hw/sd/sd.c
>> +++ b/hw/sd/sd.c
>> @@ -2058,14 +2058,12 @@ static void sd_instance_init(Object *obj)
>>      SDState *sd = SD_CARD(obj);
>>
>>      sd->enable = true;
>> -    sd->ocr_power_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sd_ocr_powerup, sd);
>>  }
>>
>>  static void sd_instance_finalize(Object *obj)
>>  {
>>      SDState *sd = SD_CARD(obj);
>>
>> -    timer_del(sd->ocr_power_timer);
>>      timer_free(sd->ocr_power_timer);
>>  }
>>
>> @@ -2098,6 +2096,15 @@ static void sd_realize(DeviceState *dev, Error **errp)
>>          }
>>          blk_set_dev_ops(sd->blk, &sd_block_ops, sd);
>>      }
>> +
>> +    sd->ocr_power_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sd_ocr_powerup, sd);
>> +}
>> +
>> +static void sd_unrealize(DeviceState *dev, Error **errp)
>> +{
>> +    SDState *sd = SD_CARD(dev);
>> +
>> +    timer_del(sd->ocr_power_timer);
>>  }
> 
> Here too the old code was doing things correctly in that
> it does a timer_del/timer_free on the timer it allocates
> in instance_init, and the new code has weirdly split the
> freeing between unrealize and finalize.

Indeed I now see it, thanks.

> 
> thanks
> -- PMM
> 



  reply	other threads:[~2020-06-05  5:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-15 15:47 [PATCH 0/2] hw: Delay timer_new() from init to realize to avoid memleaks Philippe Mathieu-Daudé
2020-02-15 15:47 ` [PATCH 1/2] hw/ipmi/bmc: Delay timer_new_ns() " Philippe Mathieu-Daudé
2020-02-16 19:43   ` Corey Minyard
2020-02-17 13:25   ` Peter Maydell
2020-02-17 13:48     ` Philippe Mathieu-Daudé
2020-02-17 14:06       ` Peter Maydell
2020-02-17 16:15         ` Philippe Mathieu-Daudé
2020-02-17 16:32           ` Peter Maydell
2020-02-17 17:12             ` Philippe Mathieu-Daudé
2020-02-17 17:14               ` Peter Maydell
2020-02-17 17:19               ` Philippe Mathieu-Daudé
2020-02-17 17:27                 ` Peter Maydell
2020-02-18  9:29                   ` Markus Armbruster
2020-02-18  9:21             ` Markus Armbruster
2020-02-17 19:33         ` Markus Armbruster
2020-02-15 15:47 ` [PATCH 2/2] hw/sd/sd: " Philippe Mathieu-Daudé
2020-02-17 13:26   ` Peter Maydell
2020-06-05  5:05     ` Philippe Mathieu-Daudé [this message]
2020-02-16  2:10 ` [PATCH 0/2] hw: Delay timer_new() " Richard Henderson

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=a36cb24a-0d0d-7772-b30e-81df474462cd@redhat.com \
    --to=philmd@redhat.com \
    --cc=minyard@acm.org \
    --cc=pannengyuan@huawei.com \
    --cc=peter.maydell@linaro.org \
    --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).