[gupnp/wip/phako/46: 1/3] linux-cm: Fds can be 0




commit 1024bb948ae047282421dbac6f670317e4a17001
Author: Jens Georg <mail jensge org>
Date:   Mon May 10 13:22:36 2021 +0200

    linux-cm: Fds can be 0

 libgupnp/gupnp-linux-context-manager.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/libgupnp/gupnp-linux-context-manager.c b/libgupnp/gupnp-linux-context-manager.c
index e96ec66..03e951d 100644
--- a/libgupnp/gupnp-linux-context-manager.c
+++ b/libgupnp/gupnp-linux-context-manager.c
@@ -943,8 +943,6 @@ create_ioctl_socket (GUPnPLinuxContextManager *self, GError **error)
         priv->fd = socket (AF_INET, SOCK_DGRAM, 0);
 
         if (priv->fd < 0) {
-                priv->fd = 0;
-
                 g_set_error_literal (error,
                                      G_IO_ERROR,
                                      g_io_error_from_errno (errno),
@@ -1045,6 +1043,7 @@ gupnp_linux_context_manager_init (GUPnPLinuxContextManager *self)
         GUPnPLinuxContextManagerPrivate *priv;
 
         priv = gupnp_linux_context_manager_get_instance_private (self);
+        priv->fd = -1;
 
         priv->nl_seq = 0;
 
@@ -1087,8 +1086,10 @@ gupnp_linux_context_manager_constructed (GObject *object)
                                NULL);
 cleanup:
         if (error) {
-                if (priv->fd > 0)
+                if (priv->fd >= 0) {
                         close (priv->fd);
+                        priv->fd = -1;
+                }
 
                 g_warning ("Failed to setup Linux context manager: %s",
                            error->message);
@@ -1129,9 +1130,9 @@ gupnp_linux_context_manager_dispose (GObject *object)
                 priv->netlink_socket = NULL;
         }
 
-        if (priv->fd != 0) {
+        if (priv->fd >= 0) {
                 close (priv->fd);
-                priv->fd = 0;
+                priv->fd = -1;
         }
 
         if (priv->interfaces) {


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