diff options
author | Simon Rettberg | 2019-08-06 11:44:27 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-08-06 11:44:27 +0200 |
commit | 48533240493c0dd970c926bbdb8939bb7d93cd14 (patch) | |
tree | b7a7e12df9c28031af2386e5cfde24d1ece15035 /src/server/uplink.c | |
parent | [SERVER] Allow uplink shutdown if bgrMinClients > image->users (diff) | |
download | dnbd3-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.
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r-- | src/server/uplink.c | 3 |
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; } |