From 040de80f5e3c5ef43c9c8d3fb478e1a0e0729691 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2018 14:36:17 +0000 Subject: [PATCH] Unix _dbus_connect_tcp_socket_with_nonce: Always goto out This will make it easier to do single-exit-path cleanup. Signed-off-by: Simon McVittie https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- dbus/dbus-sysdeps-unix.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 4bcd5325..55c91026 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1387,7 +1387,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, _dbus_error_from_errno (errno), "Failed to lookup host/port: \"%s:%s\": %s (%d)", host, port, gai_strerror(res), res); - return _dbus_socket_get_invalid (); + _dbus_socket_invalidate (&fd); + goto out; } tmp = ai; @@ -1397,7 +1398,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, { freeaddrinfo(ai); _DBUS_ASSERT_ERROR_IS_SET(error); - return _dbus_socket_get_invalid (); + _dbus_socket_invalidate (&fd); + goto out; } _DBUS_ASSERT_ERROR_IS_CLEAR(error); @@ -1405,7 +1407,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, { saved_errno = errno; _dbus_close (fd.fd, NULL); - fd.fd = -1; + _dbus_socket_invalidate (&fd); tmp = tmp->ai_next; continue; } @@ -1414,13 +1416,13 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, } freeaddrinfo(ai); - if (fd.fd == -1) + if (!_dbus_socket_is_valid (fd)) { dbus_set_error (error, _dbus_error_from_errno (saved_errno), "Failed to connect to socket \"%s:%s\" %s", host, port, _dbus_strerror(saved_errno)); - return _dbus_socket_get_invalid (); + goto out; } if (noncefile != NULL) @@ -1434,16 +1436,19 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, if (!ret) { _dbus_close (fd.fd, NULL); - return _dbus_socket_get_invalid (); + _dbus_socket_invalidate (&fd); + goto out; } } if (!_dbus_set_fd_nonblocking (fd.fd, error)) { _dbus_close (fd.fd, NULL); - return _dbus_socket_get_invalid (); + _dbus_socket_invalidate (&fd); + goto out; } +out: return fd; } -- 2.12.3