From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 0/3] require newer glib2 to enable autofree'ing of stack variables exiting scope
Date: Wed, 31 Jul 2019 15:04:29 +0100 [thread overview]
Message-ID: <87a7cui9le.fsf@linaro.org> (raw)
In-Reply-To: <20190725084341.8287-1-berrange@redhat.com>
Daniel P. Berrangé <berrange@redhat.com> writes:
> Both GCC and CLang support a C extension attribute((cleanup)) which
> allows you to define a function that is invoked when a stack variable
> exits scope. This typically used to free the memory allocated to it,
> though you're not restricted to this. For example it could be used to
> unlock a mutex.
<snip>
>
> GOOD:
> g_autofree char *wibble = g_strdup("wibble")
> ...
> return g_steal_pointer(wibble);
>
> g_steal_pointer is an inline function which simply copies
> the pointer to a new variable, and sets the original variable
> to NULL, thus avoiding cleanup.
Surely this is a particular use case where you wouldn't use g_autofree
to declare the variable as you intending to return it to the outer scope?
--
Alex Bennée
next prev parent reply other threads:[~2019-07-31 14:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 8:43 [Qemu-devel] [PATCH v2 0/3] require newer glib2 to enable autofree'ing of stack variables exiting scope Daniel P. Berrangé
2019-07-25 8:43 ` [Qemu-devel] [PATCH v2 1/3] glib: bump min required glib library version to 2.48 Daniel P. Berrangé
2019-07-25 8:43 ` [Qemu-devel] [PATCH v2 2/3] crypto: define cleanup functions for use with g_autoptr Daniel P. Berrangé
2019-07-25 8:43 ` [Qemu-devel] [PATCH v2 3/3] crypto: use auto cleanup for many stack variables Daniel P. Berrangé
2019-07-29 14:58 ` Stefan Hajnoczi
2019-07-31 12:59 ` [Qemu-devel] [PATCH v2 0/3] require newer glib2 to enable autofree'ing of stack variables exiting scope Marc-André Lureau
2019-07-31 14:04 ` Alex Bennée [this message]
2019-07-31 14:08 ` Eric Blake
2019-07-31 14:10 ` Daniel P. Berrangé
2019-07-31 14:33 ` Alex Bennée
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=87a7cui9le.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=berrange@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 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).