From 6a485ef45acbbf55f1b1cabb33069b1012dfb17b Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 13 Nov 2015 08:51:39 +0000 Subject: [PATCH] Make repeated calls to meshlink_start() without meshlink_stop() safe. --- src/meshlink.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/meshlink.c b/src/meshlink.c index b3b18074..446bc522 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -941,10 +941,17 @@ bool meshlink_start(meshlink_handle_t *mesh) { meshlink_errno = MESHLINK_EINVAL; return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n"); + pthread_mutex_lock(&(mesh->mesh_mutex)); + + if(mesh->threadstarted) { + logger(mesh, MESHLINK_DEBUG, "thread was already running\n"); + pthread_mutex_unlock(&(mesh->mesh_mutex)); + return true; + } + if(mesh->listen_socket[0].tcp.fd < 0) { logger(mesh, MESHLINK_ERROR, "Listening socket not open\n"); meshlink_errno = MESHLINK_ENETWORK; -- 2.39.5