Commit 23fb2801 authored by Simon McVittie's avatar Simon McVittie Committed by Ralf Habacker

Unix _dbus_connect_tcp_socket_with_nonce: Always goto out

This will make it easier to do single-exit-path cleanup.
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
https://bugs.freedesktop.org/show_bug.cgi?id=61922
parent ff359872
...@@ -1387,7 +1387,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, ...@@ -1387,7 +1387,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
_dbus_error_from_errno (errno), _dbus_error_from_errno (errno),
"Failed to lookup host/port: \"%s:%s\": %s (%d)", "Failed to lookup host/port: \"%s:%s\": %s (%d)",
host, port, gai_strerror(res), res); host, port, gai_strerror(res), res);
return _dbus_socket_get_invalid (); _dbus_socket_invalidate (&fd);
goto out;
} }
tmp = ai; tmp = ai;
...@@ -1397,7 +1398,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, ...@@ -1397,7 +1398,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
{ {
freeaddrinfo(ai); freeaddrinfo(ai);
_DBUS_ASSERT_ERROR_IS_SET(error); _DBUS_ASSERT_ERROR_IS_SET(error);
return _dbus_socket_get_invalid (); _dbus_socket_invalidate (&fd);
goto out;
} }
_DBUS_ASSERT_ERROR_IS_CLEAR(error); _DBUS_ASSERT_ERROR_IS_CLEAR(error);
...@@ -1405,7 +1407,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, ...@@ -1405,7 +1407,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
{ {
saved_errno = errno; saved_errno = errno;
_dbus_close (fd.fd, NULL); _dbus_close (fd.fd, NULL);
fd.fd = -1; _dbus_socket_invalidate (&fd);
tmp = tmp->ai_next; tmp = tmp->ai_next;
continue; continue;
} }
...@@ -1414,13 +1416,13 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, ...@@ -1414,13 +1416,13 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
} }
freeaddrinfo(ai); freeaddrinfo(ai);
if (fd.fd == -1) if (!_dbus_socket_is_valid (fd))
{ {
dbus_set_error (error, dbus_set_error (error,
_dbus_error_from_errno (saved_errno), _dbus_error_from_errno (saved_errno),
"Failed to connect to socket \"%s:%s\" %s", "Failed to connect to socket \"%s:%s\" %s",
host, port, _dbus_strerror(saved_errno)); host, port, _dbus_strerror(saved_errno));
return _dbus_socket_get_invalid (); goto out;
} }
if (noncefile != NULL) if (noncefile != NULL)
...@@ -1434,16 +1436,19 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, ...@@ -1434,16 +1436,19 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
if (!ret) if (!ret)
{ {
_dbus_close (fd.fd, NULL); _dbus_close (fd.fd, NULL);
return _dbus_socket_get_invalid (); _dbus_socket_invalidate (&fd);
goto out;
} }
} }
if (!_dbus_set_fd_nonblocking (fd.fd, error)) if (!_dbus_set_fd_nonblocking (fd.fd, error))
{ {
_dbus_close (fd.fd, NULL); _dbus_close (fd.fd, NULL);
return _dbus_socket_get_invalid (); _dbus_socket_invalidate (&fd);
goto out;
} }
out:
return fd; return fd;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment