From: Markus Armbruster <armbru@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: "Cédric Le Goater" <clg@redhat.com>,
qemu-devel@nongnu.org, jmarcin@redhat.com,
marcandre.lureau@redhat.com, farosas@suse.de,
berrange@redhat.com, vsementsov@yandex-team.ru,
mail@maciej.szmigiero.name, peter.maydell@linaro.org
Subject: Re: [PATCH 2.5/6] error: Explain why we don't g_autoptr(Error)
Date: Thu, 27 Nov 2025 08:01:57 +0100 [thread overview]
Message-ID: <87fra09cwq.fsf@pond.sub.org> (raw)
In-Reply-To: <aScobLHb0FQ6o_Gj@x1.local> (Peter Xu's message of "Wed, 26 Nov 2025 11:18:52 -0500")
Peter Xu <peterx@redhat.com> writes:
> On Wed, Nov 26, 2025 at 04:14:55PM +0100, Cédric Le Goater wrote:
>> On 11/26/25 15:34, Markus Armbruster wrote:
>> > Suggested-by: Peter Maydell <peter.maydell@linaro.org>
>> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> > ---
>> > include/qapi/error.h | 17 +++++++++++++++++
>> > 1 file changed, 17 insertions(+)
>> >
>> > diff --git a/include/qapi/error.h b/include/qapi/error.h
>> > index f3ce4a4a2d..fc018b4c59 100644
>> > --- a/include/qapi/error.h
>> > +++ b/include/qapi/error.h
>> > @@ -437,6 +437,23 @@ Error *error_copy(const Error *err);
>> > */
>> > void error_free(Error *err);
>> > +/*
>> > + * Note: we intentionally do not enable g_autoptr(Error) with
>> > + * G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(Error, error_free).
>> > + *
>> > + * Functions that report or propagate an error take ownership of the
>> > + * Error object. Explicit error_free() is needed when you handle an
>> > + * error in some other way. This is rare.
>> > + *
>> > + * g_autoptr(Error) would call error_free() automatically on return.
>> > + * To avoid a double-free, we'd have to manually clear the pointer
>> > + * every time we propagate or report.
>> > + *
>> > + * Thus, g_autoptr(Error) would make the rare case easier to get right
>> > + * (less prone to leaks), and the common case easier to get wrong
>> > + * (more prone to double-free).
>
> How about we further poison the auto free altogether?
>
> IIUC this should work:
>
> +extern void
> +__attribute__((error("Error should not be used with g_autoptr")))
> +error_free_poisoned(Error *err);
> +
> +G_DEFINE_AUTOPTR_CLEANUP_FUNC(Error, error_free_poisoned)
Cute. Why not. I'll post a new patch.
next prev parent reply other threads:[~2025-11-27 7:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 20:46 [PATCH for-11.0 0/6] migration: Error reporting cleanups Peter Xu
2025-11-25 20:46 ` [PATCH for-11.0 1/6] migration: Use explicit error_free() instead of g_autoptr Peter Xu
2025-11-26 6:43 ` Markus Armbruster
2025-11-25 20:46 ` [PATCH for-11.0 2/6] Revert "error: define g_autoptr() cleanup function for the Error type" Peter Xu
2025-11-26 6:45 ` Markus Armbruster
2025-11-26 7:43 ` Cédric Le Goater
2025-11-26 8:08 ` Markus Armbruster
2025-11-26 14:34 ` [PATCH 2.5/6] error: Explain why we don't g_autoptr(Error) Markus Armbruster
2025-11-26 15:14 ` Cédric Le Goater
2025-11-26 16:18 ` Peter Xu
2025-11-27 7:01 ` Markus Armbruster [this message]
2025-11-26 20:21 ` [PATCH for-11.0 2/6] Revert "error: define g_autoptr() cleanup function for the Error type" Maciej S. Szmigiero
2025-11-27 7:10 ` [PATCH 2.5/6] error: Poison g_autoptr(Error) to prevent its use Markus Armbruster
2025-11-27 15:34 ` Cédric Le Goater
2025-11-25 20:46 ` [PATCH for-11.0 3/6] migration: Make migration_connect_set_error() own the error Peter Xu
2025-11-26 7:27 ` Markus Armbruster
2025-11-28 16:58 ` Peter Xu
2025-11-25 20:46 ` [PATCH for-11.0 4/6] migration: Make multifd_send_set_error() " Peter Xu
2025-11-26 7:30 ` Markus Armbruster
2025-11-26 7:32 ` Markus Armbruster
2025-11-25 20:46 ` [PATCH for-11.0 5/6] migration: Make multifd_recv_terminate_threads() " Peter Xu
2025-11-25 20:46 ` [PATCH for-11.0 6/6] migration: Replace migrate_set_error() with migrate_error_propagate() Peter Xu
2025-11-26 7:57 ` Markus Armbruster
2025-12-01 17:32 ` Peter Xu
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=87fra09cwq.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=mail@maciej.szmigiero.name \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/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.