diff options
author | Andreas Schneider <asn@samba.org> | 2018-09-28 12:46:30 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2018-10-23 15:39:14 +0200 |
commit | 370ece1e1142be6ce0f153b12b0d8cda1dbcf100 (patch) | |
tree | 419d1cf12f1153b9494373f7083286c7cb0c68f0 /src | |
parent | 0b1a43e384e2173de0bafefd000127f3cef5b139 (diff) | |
download | socket_wrapper-370ece1e1142be6ce0f153b12b0d8cda1dbcf100.tar.gz socket_wrapper-370ece1e1142be6ce0f153b12b0d8cda1dbcf100.tar.xz socket_wrapper-370ece1e1142be6ce0f153b12b0d8cda1dbcf100.zip |
swrap: Add a mutex for resetting socket index
Fixes a helgrind error.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_wrapper.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 4f8d218..3f027dc 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -307,6 +307,9 @@ static pthread_mutex_t autobind_start_mutex; /* Mutex to guard the initialization of array of socket_info structures */ static pthread_mutex_t sockets_mutex; +/* Mutex to guard the socket reset in swrap_close() and swrap_remove_stale() */ +static pthread_mutex_t socket_reset_mutex; + /* Mutex to synchronize access to first free index in socket_info array */ static pthread_mutex_t first_free_mutex; @@ -2034,15 +2037,20 @@ static void swrap_remove_stale(int fd) SWRAP_LOG(SWRAP_LOG_TRACE, "remove stale wrapper for %d", fd); + swrap_mutex_lock(&socket_reset_mutex); + si_index = find_socket_info_index(fd); if (si_index == -1) { + swrap_mutex_unlock(&socket_reset_mutex); return; } - si = swrap_get_socket_info(si_index); - reset_socket_info_index(fd); + swrap_mutex_unlock(&socket_reset_mutex); + + si = swrap_get_socket_info(si_index); + swrap_mutex_lock(&first_free_mutex); SWRAP_LOCK_SI(si); @@ -5909,13 +5917,18 @@ static int swrap_close(int fd) int si_index; int ret; + swrap_mutex_lock(&socket_reset_mutex); + si_index = find_socket_info_index(fd); if (si_index == -1) { + swrap_mutex_unlock(&socket_reset_mutex); return libc_close(fd); } reset_socket_info_index(fd); + swrap_mutex_unlock(&socket_reset_mutex); + si = swrap_get_socket_info(si_index); swrap_mutex_lock(&first_free_mutex); @@ -6202,6 +6215,13 @@ void swrap_constructor(void) exit(-1); } + ret = socket_wrapper_init_mutex(&socket_reset_mutex); + if (ret != 0) { + SWRAP_LOG(SWRAP_LOG_ERROR, + "Failed to initialize pthread mutex"); + exit(-1); + } + ret = socket_wrapper_init_mutex(&first_free_mutex); if (ret != 0) { SWRAP_LOG(SWRAP_LOG_ERROR, |