diff options
author | Simon McVittie <smcv@collabora.com> | 2017-11-21 15:43:55 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-11-24 12:17:38 +0000 |
commit | f058394a0e29c9f04782833c6f2d3617b11906a9 (patch) | |
tree | 7f5913d53444b7d8af97c68b7f36b987b3d0b784 | |
parent | 3507b4fc12b144ed05ed33e6fa214ee487a6cb6a (diff) |
_dbus_server_new_for_tcp_socket: Simplify error unwinding
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
-rw-r--r-- | dbus/dbus-server-socket.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 9e54bc520..64cfc90d7 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -422,28 +422,26 @@ _dbus_server_new_for_tcp_socket (const char *host, DBusError *error, dbus_bool_t use_nonce) { - DBusServer *server; + DBusServer *server = NULL; DBusSocket *listen_fds = NULL; int nlisten_fds = 0, i; - DBusString address; - DBusString host_str; - DBusString port_str; + DBusString address = _DBUS_STRING_INIT_INVALID; + DBusString host_str; /* Initialized as const later, not freed */ + DBusString port_str = _DBUS_STRING_INIT_INVALID; DBusNonceFile *noncefile = NULL; _DBUS_ASSERT_ERROR_IS_CLEAR (error); - noncefile = NULL; - if (!_dbus_string_init (&address)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - return NULL; + goto failed; } if (!_dbus_string_init (&port_str)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - goto failed_0; + goto failed; } if (host == NULL) @@ -463,7 +461,7 @@ _dbus_server_new_for_tcp_socket (const char *host, if (nlisten_fds <= 0) { _DBUS_ASSERT_ERROR_IS_SET(error); - goto failed_1; + goto failed; } _dbus_string_init_const (&host_str, host); @@ -473,32 +471,32 @@ _dbus_server_new_for_tcp_socket (const char *host, !_dbus_string_append (&address, _dbus_string_get_const_data(&port_str))) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - goto failed_2; + goto failed; } if (family && (!_dbus_string_append (&address, ",family=") || !_dbus_string_append (&address, family))) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - goto failed_2; + goto failed; } if (use_nonce) { if (!_dbus_noncefile_create (&noncefile, error)) - goto failed_2; + goto failed; if (!_dbus_string_append (&address, ",noncefile=") || !_dbus_address_append_escaped (&address, _dbus_noncefile_get_path (noncefile))) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - goto failed_2; + goto failed; } } server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile, error); if (server == NULL) - goto failed_2; + goto failed; /* server has taken ownership of noncefile and the fds in listen_fds */ _dbus_string_free (&port_str); @@ -507,19 +505,18 @@ _dbus_server_new_for_tcp_socket (const char *host, return server; - failed_2: +failed: _dbus_noncefile_delete (&noncefile, NULL); - for (i = 0 ; i < nlisten_fds ; i++) - _dbus_close_socket (listen_fds[i], NULL); - dbus_free(listen_fds); + if (listen_fds != NULL) + { + for (i = 0; i < nlisten_fds; i++) + _dbus_close_socket (listen_fds[i], NULL); + dbus_free (listen_fds); + } - failed_1: _dbus_string_free (&port_str); - - failed_0: _dbus_string_free (&address); - return NULL; } |