From: Cornelia Huck <cohuck@redhat.com>
To: Michal Privoznik <mprivozn@redhat.com>
Cc: alex.williamson@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 2/2] vfio-helpers: Free QEMUVFIOState in qemu_vfio_close()
Date: Mon, 11 Nov 2019 12:15:23 +0100 [thread overview]
Message-ID: <20191111121523.4e692f1f.cohuck@redhat.com> (raw)
In-Reply-To: <14247f68a13c7b9292b91eb7df02de9b9d248544.1573468531.git.mprivozn@redhat.com>
On Mon, 11 Nov 2019 11:37:42 +0100
Michal Privoznik <mprivozn@redhat.com> wrote:
> The qemu_vfio_open_pci() allocates this QEMUVFIOState structure
> but free counterpart is missing. Since we already have
> qemu_vfio_close() which does cleanup of the state, it looks like
> a perfect place to free the structure too.
>
> ==178278== 528 (360 direct, 168 indirect) bytes in 1 blocks are definitely lost in loss record 6,605 of 6,985
> ==178278== at 0x4A35476: calloc (vg_replace_malloc.c:752)
> ==178278== by 0x51B1158: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6000.6)
> ==178278== by 0xA68613: qemu_vfio_open_pci (vfio-helpers.c:428)
> ==178278== by 0x9779EA: nvme_init (nvme.c:606)
> ==178278== by 0x97830F: nvme_file_open (nvme.c:795)
> ==178278== by 0x8E9439: bdrv_open_driver (block.c:1293)
> ==178278== by 0x8E9E1C: bdrv_open_common (block.c:1553)
> ==178278== by 0x8ED264: bdrv_open_inherit (block.c:3083)
> ==178278== by 0x8ED79D: bdrv_open (block.c:3176)
> ==178278== by 0x5DA5C1: bds_tree_init (blockdev.c:670)
> ==178278== by 0x5E2B64: qmp_blockdev_add (blockdev.c:4354)
> ==178278== by 0x5ECB1D: configure_blockdev (vl.c:1202)
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> util/vfio-helpers.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
> index 813f7ec564..5ff91c1e5c 100644
> --- a/util/vfio-helpers.c
> +++ b/util/vfio-helpers.c
> @@ -721,4 +721,5 @@ void qemu_vfio_close(QEMUVFIOState *s)
> close(s->device);
> close(s->group);
> close(s->container);
> + g_free(s);
Not sure if freeing the parameter passed in via a function called
'close' isn't too surprising... it's not that obvious that the caller
is also relinquishing its reference to the QEMUVFIOState; maybe rename
the function to qemu_vfio_close_and_free() or so?
[Looking at the blockdev code, it uses the pattern of first closing the
bs and then freeing it separately, which is a bit odd as the only call
to bdrv_close (which will eventually end up here for nvme) is
immediately followed by a g_free. Just something I noticed.]
> }
next prev parent reply other threads:[~2019-11-11 11:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-11 10:37 [PATCH 0/2] A pair of memory access problems Michal Privoznik
2019-11-11 10:37 ` [PATCH 1/2] hw/vfio/pci: Fix double free of migration_blocker Michal Privoznik
2019-11-11 10:52 ` Cornelia Huck
2019-11-11 10:37 ` [PATCH 2/2] vfio-helpers: Free QEMUVFIOState in qemu_vfio_close() Michal Privoznik
2019-11-11 11:15 ` Cornelia Huck [this message]
2019-11-12 15:25 ` Michal Privoznik
2019-11-11 14:13 ` [PATCH 0/2] A pair of memory access problems no-reply
2019-11-15 16:31 ` Alex Williamson
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=20191111121523.4e692f1f.cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=mprivozn@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.