[glib/glib-2-48] socket: set fd field to -1 after closing socket



commit 1d746b6c949b82c98c0a60dd500e6d7acb4317ca
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 4 10:40:50 2016 +0300

    socket: set fd field to -1 after closing socket
    
    This ensures that g_socket_get_fd() will return -1 after the socket has
    been closed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765959

 gio/gsocket.c      |    1 +
 gio/tests/socket.c |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index e7f2101..4961f6f 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -3285,6 +3285,7 @@ g_socket_close (GSocket  *socket,
       break;
     }
 
+  socket->priv->fd = -1;
   socket->priv->connected_read = FALSE;
   socket->priv->connected_write = FALSE;
   socket->priv->closed = TRUE;
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index a5b2573..1dba970 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -1197,6 +1197,10 @@ test_fd_reuse (void)
   g_socket_close (data->server, &error);
   g_assert_no_error (error);
 
+  g_assert_cmpint (g_socket_get_fd (client), ==, -1);
+  g_assert_cmpint (g_socket_get_fd (client2), ==, -1);
+  g_assert_cmpint (g_socket_get_fd (data->server), ==, -1);
+
   g_object_unref (data->server);
   g_object_unref (client);
   g_object_unref (client2);


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