tcpserversink: Don't assume g_socket_get_remote_address succeeds

When the client disconnects immediately after connecting, the remote
address is no longer available.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/908>
This commit is contained in:
Jan Alexander Steffens (heftig) 2020-10-30 13:52:29 +01:00
parent 69b5cb8a10
commit c4cdb6590e

View file

@ -172,14 +172,20 @@ gst_tcp_server_sink_handle_server_read (GstTCPServerSink * sink)
GInetSocketAddress *addr =
G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (client_socket,
NULL));
gchar *ip =
g_inet_address_to_string (g_inet_socket_address_get_address (addr));
if (addr) {
gchar *ip =
g_inet_address_to_string (g_inet_socket_address_get_address (addr));
GST_DEBUG_OBJECT (sink, "added new client ip %s:%u with socket %p",
ip, g_inet_socket_address_get_port (addr), client_socket);
GST_DEBUG_OBJECT (sink, "added new client ip %s:%u with socket %p",
ip, g_inet_socket_address_get_port (addr), client_socket);
g_free (ip);
g_object_unref (addr);
g_free (ip);
g_object_unref (addr);
} else {
/* This can happen when the client immediately closes the connection */
GST_DEBUG_OBJECT (sink, "added new client (no address) with socket %p",
client_socket);
}
}
#endif