gnetworkmonitornetlink: Close the socket after disconnecting its GSources

`read_netlink_messages()` is the callback attached to the netlink socket
(G_IO_IN). It calls `g_socket_receive_message()`. There is a race
condition that if the socket is closed while there is a pending call, we
will try to receive on a closed socket, which fails.

To avoid this, we switch the order of the operations around: first
destroy the source and then close the socket.
This commit is contained in:
Iain Lane 2018-09-10 12:00:46 +01:00 committed by Philip Withnall
parent 8b26ad22d4
commit 7e413f810c

View File

@ -435,12 +435,6 @@ g_network_monitor_netlink_finalize (GObject *object)
{
GNetworkMonitorNetlink *nl = G_NETWORK_MONITOR_NETLINK (object);
if (nl->priv->sock)
{
g_socket_close (nl->priv->sock, NULL);
g_object_unref (nl->priv->sock);
}
if (nl->priv->source)
{
g_source_destroy (nl->priv->source);
@ -453,6 +447,12 @@ g_network_monitor_netlink_finalize (GObject *object)
g_source_unref (nl->priv->dump_source);
}
if (nl->priv->sock)
{
g_socket_close (nl->priv->sock, NULL);
g_object_unref (nl->priv->sock);
}
g_clear_pointer (&nl->priv->context, g_main_context_unref);
g_clear_pointer (&nl->priv->dump_networks, g_ptr_array_unref);