swrap: Rearrange swrap_close
authorAnoop C S <anoopcs@redhat.com>
Thu, 13 Jul 2017 09:50:15 +0000 (15:20 +0530)
committerAndreas Schneider <asn@samba.org>
Wed, 2 May 2018 12:23:34 +0000 (14:23 +0200)
In preparation to implement thread safety, re-ordering lines
of code to properly align to locking calls.

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 ad83111a11e4300fe040f73a5f8f01264a90fc50..f1f0036d4865564c297c14947d791bde416cf549 100644 (file)
@@ -5692,15 +5692,19 @@ static int swrap_close(int fd)
        }
 
        si_index = fi->si_index;
+       si = swrap_get_socket_info(si_index);
 
        SWRAP_DLIST_REMOVE(socket_fds, fi);
-       free(fi);
 
        ret = libc_close(fd);
 
-       si = swrap_get_socket_info(si_index);
+       swrap_set_next_free(si, first_free);
+       first_free = si_index;
+
        swrap_dec_refcount(si);
 
+       free(fi);
+
        if (swrap_get_refcount(si) > 0) {
                /* there are still references left */
                return ret;
@@ -5719,9 +5723,6 @@ static int swrap_close(int fd)
                unlink(si->un_addr.sun_path);
        }
 
-       swrap_set_next_free(si, first_free);
-       first_free = si_index;
-
        return ret;
 }