Signed-off-by: Kevin Wolf <kw...@redhat.com> --- After rebasing this I saw that Anthony already committed a fix that is very close to my v1. I don't intend to actually change that code, but as I've already done this, just for comparison what it would look like with error propagation. Is this what you meant? I find the result more confusing, to be honest. --- util/qemu-sockets.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 3f12296..f231e9c 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -359,6 +359,7 @@ int inet_connect_opts(QemuOpts *opts, Error **errp, int sock = -1; bool in_progress; ConnectState *connect_state = NULL; + Error *local_err = NULL; res = inet_parse_connect_opts(opts, errp); if (!res) { @@ -373,15 +374,17 @@ int inet_connect_opts(QemuOpts *opts, Error **errp, } for (e = res; e != NULL; e = e->ai_next) { - if (error_is_set(errp)) { - error_free(*errp); - *errp = NULL; - } + + Error *ret_err = NULL; + if (connect_state != NULL) { connect_state->current_addr = e; } - sock = inet_connect_addr(e, &in_progress, connect_state, errp); - if (in_progress) { + sock = inet_connect_addr(e, &in_progress, connect_state, &ret_err); + if (error_is_set(&ret_err)) { + error_propagate(&local_err, ret_err); + } else if (in_progress) { + error_free(local_err); return sock; } else if (sock >= 0) { /* non blocking socket immediate success, call callback */ @@ -393,6 +396,11 @@ int inet_connect_opts(QemuOpts *opts, Error **errp, } g_free(connect_state); freeaddrinfo(res); + if (sock >= 0) { + error_free(local_err); + } else { + error_propagate(errp, local_err); + } return sock; } -- 1.8.1.4