From: Guus Sliepen Date: Fri, 13 Nov 2015 08:51:39 +0000 (+0000) Subject: Make repeated calls to meshlink_start() without meshlink_stop() safe. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=6a485ef45acbbf55f1b1cabb33069b1012dfb17b;p=meshlink Make repeated calls to meshlink_start() without meshlink_stop() safe. --- 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;