summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-08-06 11:44:27 +0200
committerSimon Rettberg2019-08-06 11:44:27 +0200
commit48533240493c0dd970c926bbdb8939bb7d93cd14 (patch)
treeb7a7e12df9c28031af2386e5cfde24d1ece15035
parent[SERVER] Allow uplink shutdown if bgrMinClients > image->users (diff)
downloaddnbd3-48533240493c0dd970c926bbdb8939bb7d93cd14.tar.gz
dnbd3-48533240493c0dd970c926bbdb8939bb7d93cd14.tar.xz
dnbd3-48533240493c0dd970c926bbdb8939bb7d93cd14.zip
[SERVER] Fix: Client thread could destroy sendMutex while in use
Fix a race condition where the client thread tears down the client struct including the sendMutex while the uplink thead is currently holding the lock, trying to send data to the client.
-rw-r--r--src/server/uplink.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/server/uplink.c b/src/server/uplink.c
index aa5228c..f58b019 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -153,6 +153,9 @@ void uplink_removeClient(dnbd3_connection_t *uplink, dnbd3_client_t *client)
mutex_lock( &uplink->queueLock );
for (int i = uplink->queueLen - 1; i >= 0; --i) {
if ( uplink->queue[i].client == client ) {
+ // Make sure client doesn't get destroyed while we're sending it data
+ mutex_lock( &client->sendMutex );
+ mutex_unlock( &client->sendMutex );
uplink->queue[i].client = NULL;
uplink->queue[i].status = ULR_FREE;
}