swrap: remember the libc_close() errno in swrap_close()
authorStefan Metzmacher <metze@samba.org>
Wed, 17 Feb 2021 11:14:06 +0000 (12:14 +0100)
committerAndreas Schneider <asn@samba.org>
Mon, 15 Mar 2021 07:04:58 +0000 (08:04 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14640

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 3bf60f1b557f5d103b7783bcc19c706ac2a9e87c..61dce978ce64c3242e8c3b1c92f8f443487fd631 100644 (file)
@@ -7421,6 +7421,7 @@ static int swrap_close(int fd)
 {
        struct socket_info *si = NULL;
        int si_index;
+       int ret_errno = errno;
        int ret;
 
        swrap_mutex_lock(&socket_reset_mutex);
@@ -7440,6 +7441,9 @@ static int swrap_close(int fd)
        SWRAP_LOCK_SI(si);
 
        ret = libc_close(fd);
+       if (ret == -1) {
+               ret_errno = errno;
+       }
 
        swrap_dec_refcount(si);
 
@@ -7474,6 +7478,7 @@ out:
        swrap_mutex_unlock(&first_free_mutex);
        swrap_mutex_unlock(&socket_reset_mutex);
 
+       errno = ret_errno;
        return ret;
 }