qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Shannon Zhao <zhaoshenglong@huawei.com>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Michael Tokarev <mjt@tls.msk.ru>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Shannon Zhao <shannon.zhao@linaro.org>
Subject: Re: [Qemu-devel] [PATCH 01/29] hw/ide/ahci.c: Fix memory leak spotted by valgrind
Date: Thu, 28 May 2015 13:39:00 +0100	[thread overview]
Message-ID: <CAFEAcA8QXBPj3-mMWfTHUM+88q1QPzgOk49rZ1thVfvb+uiptA@mail.gmail.com> (raw)
In-Reply-To: <5567091A.5050901@huawei.com>

On 28 May 2015 at 13:24, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
>
>
> On 2015/5/28 20:16, Peter Maydell wrote:
>> On 28 May 2015 at 13:08, Shannon Zhao <zhaoshenglong@huawei.com> wrote:
>>> > From: Shannon Zhao <shannon.zhao@linaro.org>
>>> > --- a/hw/ide/ahci.c
>>> > +++ b/hw/ide/ahci.c
>>> > @@ -1367,6 +1367,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports)
>>> >          ad->port.dma->ops = &ahci_dma_ops;
>>> >          ide_register_restart_cb(&ad->port);
>>> >      }
>>> > +    g_free(irqs);
>>> >  }
>> Freeing the return value of qemu_allocate_irqs()
>> directly rather than using qemu_free_irqs() looks
>> dubious to me.
>
> qemu_free_irqs() will free the return value self of qemu_allocate_irqs()
> and also will free all the contents of this array while some of them are
> still in use.

Yes, but you're still looking into the internal implementation
details of this API, which is what I'm suggesting is dubious.

For instance, in this case, why are we calling
qemu_allocate_irqs() in the first place, rather than
just calling qemu_allocate_irq() inside the for() loop in
ahci_init()?

If code wants to deal with the array of irqs as an array,
it should probably be saving the pointer somewhere in its
state struct and freeing the whole thing on deinit. If it
doesn't actually want an array of irqs (as here) it should
probably not be calling qemu_allocate_irqs() in the first
place.

thanks
-- PMM

  reply	other threads:[~2015-05-28 12:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28 12:08 [Qemu-devel] [PATCH 00/29] Fix memory leak relevant to calling qemu_allocate_irqs Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 01/29] hw/ide/ahci.c: Fix memory leak spotted by valgrind Shannon Zhao
2015-05-28 12:16   ` Peter Maydell
2015-05-28 12:24     ` Shannon Zhao
2015-05-28 12:39       ` Peter Maydell [this message]
2015-05-28 12:08 ` [Qemu-devel] [PATCH 02/29] hw/ide/cmd646.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 03/29] hw/i386/pc: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 04/29] hw/i386/pc_q35.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 05/29] hw/isa/lpc_ich9.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 06/29] hw/isa/i82378.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 07/29] hw/timer/arm_timer.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 08/29] hw/intc/exynos4210_gic.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 09/29] hw/sparc/leon3.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 10/29] hw/sparc/sun4m.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 11/29] hw/ppc/mac_oldworld.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 12/29] hw/ppc/ppc440_bamboo.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 13/29] hw/ppc/prep.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 14/29] hw/mips/mips_int.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 15/29] hw/mips/mips_jazz.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 16/29] hw/lm32/lm32_boards.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 17/29] hw/lm32/milkymist.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 18/29] hw/m68k/mcf5206.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 19/29] hw/openrisc/pic_cpu.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 20/29] hw/unicore32/puv3.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 21/29] hw/sh4/r2d.c: " Shannon Zhao
2015-05-28 12:46   ` Peter Maydell
2015-05-29  2:11     ` Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 22/29] hw/alpha/typhoon.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 23/29] hw/arm/nseries.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 24/29] hw/arm/omap_sx1.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 25/29] hw/arm/palm.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 26/29] hw/arm/spitz.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 27/29] hw/arm/tosa.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 28/29] hw/display/tc6393xb.c: " Shannon Zhao
2015-05-28 12:08 ` [Qemu-devel] [PATCH 29/29] hw/s390x/sclpcpu.c: " Shannon Zhao
2015-05-28 13:11   ` Cornelia Huck
2015-05-30  7:27     ` Shannon Zhao
2015-05-28 13:21   ` Peter Maydell
2015-05-30 10:34   ` Paolo Bonzini
2015-05-30 11:07     ` Shannon Zhao
2015-05-28 12:34 ` [Qemu-devel] [PATCH 00/29] Fix memory leak relevant to calling qemu_allocate_irqs Michael Tokarev
2015-05-29  2:21   ` Shannon Zhao

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=CAFEAcA8QXBPj3-mMWfTHUM+88q1QPzgOk49rZ1thVfvb+uiptA@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=shannon.zhao@linaro.org \
    --cc=zhaoshenglong@huawei.com \
    /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).