swrap: Update free-list only when refcount is zero
authorAnoop C S <anoopcs@redhat.com>
Wed, 31 Jan 2018 17:16:23 +0000 (22:46 +0530)
committerAndreas Schneider <asn@samba.org>
Wed, 2 May 2018 14:31:42 +0000 (16:31 +0200)
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index ed42b2d2bbdac169123648b6a4e142ecda1ba175..6c9ec510ed3c15fdac9043c3945c735e8d7bf499 100644 (file)
@@ -2015,8 +2015,6 @@ static void swrap_remove_stale(int fd)
 
        SWRAP_DLIST_REMOVE(socket_fds, fi);
 
-       swrap_set_next_free(si, first_free);
-       first_free = si_index;
        swrap_dec_refcount(si);
 
        free(fi);
@@ -2029,6 +2027,9 @@ static void swrap_remove_stale(int fd)
                unlink(si->un_addr.sun_path);
        }
 
+       swrap_set_next_free(si, first_free);
+       first_free = si_index;
+
 out:
        SWRAP_UNLOCK_SI(si);
        SWRAP_UNLOCK(first_free);
@@ -5887,9 +5888,6 @@ static int swrap_close(int fd)
 
        ret = libc_close(fd);
 
-       swrap_set_next_free(si, first_free);
-       first_free = si_index;
-
        swrap_dec_refcount(si);
 
        free(fi);
@@ -5912,6 +5910,9 @@ static int swrap_close(int fd)
                unlink(si->un_addr.sun_path);
        }
 
+       swrap_set_next_free(si, first_free);
+       first_free = si_index;
+
 out:
        SWRAP_UNLOCK_SI(si);
        SWRAP_UNLOCK(first_free);