From 93a7614d2aa368a9799d6e39c73542a3998e70bf Mon Sep 17 00:00:00 2001 From: sairoop-elear Date: Fri, 6 Sep 2019 16:06:16 +0530 Subject: [PATCH] Fix deadlock during discovery failure --- src/discovery.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/discovery.c b/src/discovery.c index 9064523c..481b2f28 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -341,6 +341,7 @@ static void discovery_log_cb(CattaLogLevel level, const char *txt) { } static void *discovery_loop(void *userdata) { + bool status = false; meshlink_handle_t *mesh = userdata; assert(mesh != NULL); @@ -397,13 +398,17 @@ static void *discovery_loop(void *userdata) { goto fail; } + status = true; + +fail: + pthread_mutex_lock(&mesh->discovery_mutex); pthread_cond_broadcast(&mesh->discovery_cond); pthread_mutex_unlock(&mesh->discovery_mutex); - catta_simple_poll_loop(mesh->catta_poll); - -fail: + if(status) { + catta_simple_poll_loop(mesh->catta_poll); + } if(mesh->catta_browser != NULL) { catta_s_service_browser_free(mesh->catta_browser); -- 2.39.5