From: Guus Sliepen Date: Wed, 25 Sep 2019 05:42:00 +0000 (+0200) Subject: Add missing mutex locks. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=359de4c8f0085f6b1af47b9d9e92b3ddc6c47cab;p=meshlink Add missing mutex locks. meshlink_channel_close() and meshlink_channel_shutdown() did not lock the mutex, which could cause some race conditions. --- diff --git a/src/meshlink.c b/src/meshlink.c index bb77ccf8..958c23e4 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -3152,7 +3152,9 @@ void meshlink_channel_shutdown(meshlink_handle_t *mesh, meshlink_channel_t *chan return; } + pthread_mutex_lock(&mesh->mesh_mutex); utcp_shutdown(channel->c, direction); + pthread_mutex_unlock(&mesh->mesh_mutex); } void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel) { @@ -3161,6 +3163,8 @@ void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel return; } + pthread_mutex_lock(&mesh->mesh_mutex); + utcp_close(channel->c); /* Clean up any outstanding AIO buffers. */ @@ -3176,6 +3180,8 @@ void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel free(aio); } + pthread_mutex_unlock(&mesh->mesh_mutex); + free(channel); }