swrap: slightly cleanup logic in swrap_close
authorMichael Adam <obnox@samba.org>
Tue, 25 Oct 2016 11:42:05 +0000 (13:42 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 25 Oct 2016 12:55:13 +0000 (14:55 +0200)
This moves the libc_close() to one central point, thereby
grouping the fd-related operations together and the the
socket-info related operations after that.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 8ac838b8c5e7a4d8efbc49303da836e7a2ae5d84..196154978e5f4ecac675d8e856f5f49fd2375e3a 100644 (file)
@@ -5363,20 +5363,20 @@ static int swrap_close(int fd)
        SWRAP_DLIST_REMOVE(socket_fds, fi);
        free(fi);
 
+       ret = libc_close(fd);
+
        si = &sockets[si_index];
        si->refcount--;
 
        if (si->refcount > 0) {
                /* there are still references left */
-               return libc_close(fd);
+               return ret;
        }
 
        if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) {
                swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0);
        }
 
-       ret = libc_close(fd);
-
        if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) {
                swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0);
                swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0);