[glib/glib-2-58: 2/3] gnetworkmonitornetlink: Close the socket after disconnecting its GSources



commit 7e413f810cc6925a39a5e577581fb308804ed8a8
Author: Iain Lane <iainl gnome org>
Date:   Mon Sep 10 12:00:46 2018 +0100

    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.

 gio/gnetworkmonitornetlink.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gio/gnetworkmonitornetlink.c b/gio/gnetworkmonitornetlink.c
index f889a3b64..3841e69e1 100644
--- a/gio/gnetworkmonitornetlink.c
+++ b/gio/gnetworkmonitornetlink.c
@@ -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);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]