From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Laurent Vivier <laurent@vivier.eu>
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"qemu trival" <qemu-trivial@nongnu.org>,
"Pan Nengyuan" <pannengyuan@huawei.com>,
QEMU <qemu-devel@nongnu.org>,
"Marc-André Lureau" <marcandre.lureau@gmail.com>,
"Euler Robot" <euler.robot@huawei.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: Re: [PATCH] core/qdev: fix memleak in qdev_get_gpio_out_connector()
Date: Mon, 9 Mar 2020 10:48:51 +0000 [thread overview]
Message-ID: <20200309104851.GD3033513@redhat.com> (raw)
In-Reply-To: <87b027ab-7bed-249a-08a2-2c27fdd05a31@vivier.eu>
On Mon, Mar 09, 2020 at 10:16:28AM +0100, Laurent Vivier wrote:
> Le 07/03/2020 à 11:39, Marc-André Lureau a écrit :
> > Hi
> >
> > On Sat, Mar 7, 2020 at 3:53 AM Pan Nengyuan <pannengyuan@huawei.com> wrote:
> >>
> >> Fix a memory leak in qdev_get_gpio_out_connector().
> >>
> >> Reported-by: Euler Robot <euler.robot@huawei.com>
> >> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> >
> > good catch,
> > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> trivial question:
>
> Why do we prefer g_autofree() to the g_free() function?
The g_autofree annotation guarantees that g_free() gets invoked
when the variable goes out of scope, in all code paths.
This avoids the need to do the classic "goto cleanup;" jumps
with manuall free calls. So as well as simplifying code it
makes it less error prone in general. Of course the method
in this patch is only three lines long so you don't really
see the benefits, but there's also no real harm. So I'd
personally always pick g_autofree in situations where it
is usable, as it is a good habit to be in when you get to
more complex codepaths.
> >> ---
> >> hw/core/qdev.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> >> index 3937d1eb1a..85f062def7 100644
> >> --- a/hw/core/qdev.c
> >> +++ b/hw/core/qdev.c
> >> @@ -557,7 +557,7 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
> >>
> >> qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n)
> >> {
> >> - char *propname = g_strdup_printf("%s[%d]",
> >> + g_autofree char *propname = g_strdup_printf("%s[%d]",
> >> name ? name : "unnamed-gpio-out", n);
> >>
> >> qemu_irq ret = (qemu_irq)object_property_get_link(OBJECT(dev), propname,
> >> --
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:[~2020-03-09 10:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-07 3:07 [PATCH] core/qdev: fix memleak in qdev_get_gpio_out_connector() Pan Nengyuan
2020-03-07 3:16 ` no-reply
2020-03-07 10:39 ` Marc-André Lureau
2020-03-09 9:16 ` Laurent Vivier
2020-03-09 10:41 ` Pan Nengyuan
2020-03-09 10:49 ` Laurent Vivier
2020-03-09 10:48 ` Daniel P. Berrangé [this message]
2020-03-09 12:05 ` Laurent Vivier
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=20200309104851.GD3033513@redhat.com \
--to=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=euler.robot@huawei.com \
--cc=laurent@vivier.eu \
--cc=marcandre.lureau@gmail.com \
--cc=pannengyuan@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=zhang.zhanghailiang@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).