From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH] vhost-user-input: use free(elem) instead of g_free(elem)
Date: Wed, 20 Nov 2019 11:48:56 +0000 [thread overview]
Message-ID: <20191120114856.GG2785116@redhat.com> (raw)
In-Reply-To: <20191119111626.112206-1-stefanha@redhat.com>
On Tue, Nov 19, 2019 at 11:16:26AM +0000, Stefan Hajnoczi wrote:
> The virtqueue element returned by vu_queue_pop() is allocated using
> malloc(3) by virtqueue_alloc_element(). Use the matching free(3)
> function instead of glib's g_free().
Just as an FYI, since glib 2.46 g_malloc is hardcoded to use the
system allocator, so it is now guaranteed that g_malloc/malloc
and g_free/free are safely interchangable. I recently got this
clarified in the glib docs:
https://gitlab.gnome.org/GNOME/glib/merge_requests/1099//diffs
QEMU mandates 2.48 so we are now safe in that regard
For readability/sanity sake I'd still suggest matching functions
but it is not a functional danger any more. Even when it was a
risk, that risk only arose if you called GLib's API for installing
a custom allocator callback which QEMU never did, so it was always
a non-issue.
Where this is most helpful is in exchanging allocated data with
3rd party libraries that don't use glib. We no longer have to
worry about dup'ing memory going in/out libraries not using
glib's allocators.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> contrib/vhost-user-input/main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/vhost-user-input/main.c b/contrib/vhost-user-input/main.c
> index 449fd2171a..ef4b7769f2 100644
> --- a/contrib/vhost-user-input/main.c
> +++ b/contrib/vhost-user-input/main.c
> @@ -77,7 +77,7 @@ static void vi_input_send(VuInput *vi, struct virtio_input_event *event)
> len = iov_from_buf(elem->in_sg, elem->in_num,
> 0, &vi->queue[i].event, sizeof(virtio_input_event));
> vu_queue_push(dev, vq, elem, len);
> - g_free(elem);
> + free(elem);
> }
>
> vu_queue_notify(&vi->dev.parent, vq);
> @@ -153,7 +153,7 @@ static void vi_handle_sts(VuDev *dev, int qidx)
> 0, &event, sizeof(event));
> vi_handle_status(vi, &event);
> vu_queue_push(dev, vq, elem, len);
> - g_free(elem);
> + free(elem);
> }
>
> vu_queue_notify(&vi->dev.parent, vq);
> --
> 2.23.0
>
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2019-11-20 12:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-19 11:16 [PATCH] vhost-user-input: use free(elem) instead of g_free(elem) Stefan Hajnoczi
2019-11-19 11:52 ` Marc-André Lureau
2019-11-20 9:37 ` Philippe Mathieu-Daudé
2019-11-20 11:41 ` Stefan Hajnoczi
2019-11-20 12:04 ` Michael S. Tsirkin
2019-11-20 11:48 ` Daniel P. Berrangé [this message]
2019-11-21 13:51 ` Stefan Hajnoczi
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=20191120114856.GG2785116@redhat.com \
--to=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).