From: Laszlo Ersek <lersek@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [RFC PATCH] qemu-socket: Use local error variable
Date: Fri, 15 Mar 2013 19:39:04 +0100 [thread overview]
Message-ID: <51436AC8.7030701@redhat.com> (raw)
In-Reply-To: <20130315175550.GE2418@dhcp-200-207.str.redhat.com>
On 03/15/13 18:55, Kevin Wolf wrote:
> However this won't be the last time that I have to deal with an Error
> object, so I thought I'd check what is good practice. Seems no such
> thing has established yet, which is an answer, even though not the one I
> was hoping for.
What I've gathered from discussions with Luiz and Markus, there is
indeed no official Error*-handling-style.
FWIW personally I think that my suggestion was quite close to a good
(I'd even hazard "elegant") approach. I did notice that it would look
terrible in the function at hand if applied directly (I actually started
to code it up as an "illustrative patch"). For the emergent fugliness I
blamed inet_connect_opts()'s current structure (several exit points,
transfer of ownership without documentation, etc).
So for the illustration I would have had to restructure the function.
That in turn would have depended on me understanding the non-trivial
life cycle (ownership) of "connect_state" / "res" under the different
return conditions. (That is, when we bail out due to "in progress", the
"connect_state" and the rest of the addrinfo list is:
- either referenced elsewhere,
- or freed,
- or leaked currently.)
I didn't (don't) have time/energy for that -- my bad.
In general, murky ownership transfers seem to be characteristic of qemu.
When a function allocates dynamic memory, it should:
(1) either free it unconditionally (temp working space),
(2) free it on error, return it on success (constructor),
(3) transfer the ownership by function call (huge comment or telling
function name). This includes any refcount increments by the callee.
... The function name "inet_connect_addr" tells us nothing about
qemu_set_fd_handler2() transferring the ownership of "connect_state"
(and the off-hanging addrinfo list) to the global "io_handlers".
inet_connect_opts
inet_connect_addr
qemu_set_fd_handler2
ownership transfer in one case
release stuff in two other cases
Thanks,
Laszlo
next prev parent reply other threads:[~2013-03-15 18:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-06 10:48 [Qemu-devel] [PATCH] qemu-sockets: Fix assertion failure Kevin Wolf
2013-03-06 11:04 ` Paolo Bonzini
2013-03-06 11:11 ` Kevin Wolf
2013-03-06 14:46 ` Laszlo Ersek
2013-03-06 15:04 ` Paolo Bonzini
2013-03-06 15:19 ` Kevin Wolf
2013-03-06 15:38 ` Laszlo Ersek
2013-03-06 15:47 ` Kevin Wolf
2013-03-06 16:04 ` Laszlo Ersek
2013-03-06 15:59 ` Markus Armbruster
2013-03-06 16:43 ` Paolo Bonzini
2013-03-14 14:57 ` [Qemu-devel] [RFC PATCH] qemu-socket: Use local error variable Kevin Wolf
2013-03-14 15:52 ` Laszlo Ersek
2013-03-15 8:37 ` Kevin Wolf
2013-03-15 16:55 ` Laszlo Ersek
2013-03-15 17:55 ` Kevin Wolf
2013-03-15 18:39 ` Laszlo Ersek [this message]
2013-03-19 20:34 ` [Qemu-devel] [PATCH] qemu-sockets: Fix assertion failure Luiz Capitulino
2013-03-20 8:39 ` Kevin Wolf
2013-03-20 12:57 ` Luiz Capitulino
2013-03-20 13:37 ` Kevin Wolf
2013-03-20 13:52 ` Luiz Capitulino
2013-03-06 15:05 ` Markus Armbruster
2013-03-06 15:05 ` [Qemu-devel] Error ** parameter conventions (was: [PATCH] qemu-sockets: Fix assertion failure) Markus Armbruster
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=51436AC8.7030701@redhat.com \
--to=lersek@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@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).