Commit fa123560 authored by Simon McVittie's avatar Simon McVittie

_dbus_transport_new_for_socket: Simplify with _DBUS_STRING_INIT_INVALID

This is one of the few places that has test coverage for all the OOM
code paths. It was also one of the worst (most complicated)
error-unwinding locations, with labels failed_0 up to failed_4.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89104
parent e49a21e3
......@@ -1293,35 +1293,40 @@ _dbus_transport_new_for_socket (DBusSocket fd,
const DBusString *address)
{
DBusTransportSocket *socket_transport;
DBusString invalid = _DBUS_STRING_INIT_INVALID;
socket_transport = dbus_new0 (DBusTransportSocket, 1);
if (socket_transport == NULL)
return NULL;
/* So they can be "freed" without error */
socket_transport->encoded_outgoing = invalid;
socket_transport->encoded_incoming = invalid;
if (!_dbus_string_init (&socket_transport->encoded_outgoing))
goto failed_0;
goto failed;
if (!_dbus_string_init (&socket_transport->encoded_incoming))
goto failed_1;
goto failed;
socket_transport->write_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
DBUS_WATCH_WRITABLE,
FALSE,
NULL, NULL, NULL);
if (socket_transport->write_watch == NULL)
goto failed_2;
goto failed;
socket_transport->read_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
DBUS_WATCH_READABLE,
FALSE,
NULL, NULL, NULL);
if (socket_transport->read_watch == NULL)
goto failed_3;
goto failed;
if (!_dbus_transport_init_base (&socket_transport->base,
&socket_vtable,
server_guid, address))
goto failed_4;
goto failed;
#ifdef HAVE_UNIX_FD_PASSING
_dbus_auth_set_unix_fd_possible(socket_transport->base.auth, _dbus_socket_can_pass_unix_fd(fd));
......@@ -1336,17 +1341,21 @@ _dbus_transport_new_for_socket (DBusSocket fd,
return (DBusTransport*) socket_transport;
failed_4:
_dbus_watch_invalidate (socket_transport->read_watch);
_dbus_watch_unref (socket_transport->read_watch);
failed_3:
_dbus_watch_invalidate (socket_transport->write_watch);
_dbus_watch_unref (socket_transport->write_watch);
failed_2:
failed:
if (socket_transport->read_watch != NULL)
{
_dbus_watch_invalidate (socket_transport->read_watch);
_dbus_watch_unref (socket_transport->read_watch);
}
if (socket_transport->write_watch != NULL)
{
_dbus_watch_invalidate (socket_transport->write_watch);
_dbus_watch_unref (socket_transport->write_watch);
}
_dbus_string_free (&socket_transport->encoded_incoming);
failed_1:
_dbus_string_free (&socket_transport->encoded_outgoing);
failed_0:
dbus_free (socket_transport);
return NULL;
}
......
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