From: Max Reitz <mreitz@redhat.com>
To: "BALATON Zoltan" <balaton@eik.bme.hu>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: qemu-ppc <qemu-ppc@nongnu.org>, John Snow <jsnow@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Qemu-block <qemu-block@nongnu.org>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: Coverity CID 1421984
Date: Mon, 23 Mar 2020 14:26:13 +0100 [thread overview]
Message-ID: <4b6c74d7-6b3d-72a4-999a-1d97287fb324@redhat.com> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2003231359420.14974@zero.eik.bme.hu>
[-- Attachment #1.1: Type: text/plain, Size: 2604 bytes --]
On 23.03.20 14:11, BALATON Zoltan wrote:
> On Mon, 23 Mar 2020, Philippe Mathieu-Daudé wrote:
>> Cc'ing qemu-ppc since this is restricted to the aCube Sam460ex board.
>> On 3/23/20 12:46 PM, Max Reitz wrote:
>>> Hi,
>>>
>>> I was triaging new Coverity block layer reports today, and one that
>>> seemed like a real bug was CID 1421984:
>>>
>>> It complains about a memleak in sii3112_pci_realize() in
>>> hw/ide/sii3112.c, specifically about @irq being leaked (it’s allocated
>>> by qemu_allocate_irqs(), but never put anywhere or freed).
>>>
>>> I’m not really well-versed in anything under hw/ide, so I was wondering
>>> whether you agree it’s a bug and whether you know the correct way to fix
>>> it. (I assume it’s just a g_free(irqs), but maybe there’s a more
>>> specific way that’s applicable here.)
>>
>> What does other devices is hold a reference in the DeviceState
>> (SiI3112PCIState) to make static analyzers happy.
>
> Other IDE devices such as ahci and cmd646 seem to free it at the end of
> the init function after calling ide_init2 with it. However it's not
> clear to me how all this is supposed to work. Ahci does for example:
>
> qemu_irq *irqs = qemu_allocate_irqs(ahci_irq_set, s, s->ports);
> for (i = 0; i < s->ports; i++) {
> ide_init2(&ad->port, irqs[i]);
> }
> g_free(irqs);
>
> So it allocates an array of s->ports irqs then only frees a single
> element?
It doesn’t free a single element, it frees the array.
> Also aren't these needed after ide_init2 to actually raise the
> irq or are these end up copied to the irq field of the BMDMAState
> sonehow? Where will that be freed?
I don’t know where the array elements end up, but they aren’t freed by
the g_free().
(irqs is an array of pointers, so freeing the array does not touch its
elements, specifically it doesn’t free what those pointers point to.)
>> Ideally we should free such memory in the DeviceUnrealize handler, but
>> we in the reality we only care for hotunpluggable devices.
>> PCI devices usually are. There is a trick however, you can mark
>> overwrite the DeviceClass::hotpluggable field in sii3112_pci_class_init:
>>
>> dc->hotpluggable = false;
>
> If the above is correct then simply adding g_free(irq) after the loop at
> end of sii3112_pci_realize should be enough but I can't tell if that's
> correct. Setting hotpluggable to false does not seem to be a good fix.
Well, if other code just uses g_free(irqs), it sounds good to me. But
again, I don’t know anything about this code so far.
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-03-23 13:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 11:46 Coverity CID 1421984 Max Reitz
2020-03-23 11:58 ` Philippe Mathieu-Daudé
2020-03-23 13:11 ` BALATON Zoltan
2020-03-23 13:26 ` Max Reitz [this message]
2020-03-23 13:35 ` Peter Maydell
2020-03-23 14:06 ` BALATON Zoltan
2020-03-23 14:35 ` Peter Maydell
2020-03-23 14:43 ` BALATON Zoltan
2020-03-23 14:46 ` Peter Maydell
2020-03-23 15:28 ` BALATON Zoltan
2020-03-23 15:33 ` Peter Maydell
2020-03-23 15:28 ` Philippe Mathieu-Daudé
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=4b6c74d7-6b3d-72a4-999a-1d97287fb324@redhat.com \
--to=mreitz@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=david@gibson.dropbear.id.au \
--cc=jsnow@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).