]> git.meshlink.io Git - meshlink/commitdiff
Add missing mutex locks.
authorGuus Sliepen <guus@meshlink.io>
Wed, 25 Sep 2019 05:42:00 +0000 (07:42 +0200)
committerGuus Sliepen <guus@meshlink.io>
Wed, 25 Sep 2019 05:42:00 +0000 (07:42 +0200)
meshlink_channel_close() and meshlink_channel_shutdown() did not lock
the mutex, which could cause some race conditions.

src/meshlink.c

index bb77ccf85da0ad8687d8520b76278738df1ddf12..958c23e4d83c14cc748fcf3cbb162195395234f0 100644 (file)
@@ -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);
 }