diff --git a/src/rbus/rbus_element.c b/src/rbus/rbus_element.c index 8658af1c..60cb5f1d 100644 --- a/src/rbus/rbus_element.c +++ b/src/rbus/rbus_element.c @@ -392,17 +392,14 @@ elementNode* retrieveElement(elementNode* root, const char* elmentName) char* saveptr = NULL; elementNode* currentNode = root; elementNode* nextNode = NULL; - int tokenFound = 0; - - LOCK(); + int tokenFound = 0; RBUSLOG_DEBUG("Request to retrieve element [%s]", elmentName); if(currentNode == NULL) { return NULL; } - + LOCK(); name = strdup(elmentName); - nextNode = currentNode->child; /*TODO if name is a table row with an alias containing a dot, this will break (e.g. "Foo.[alias.1]")*/ @@ -496,14 +493,13 @@ elementNode* retrieveInstanceElementEx(rbusHandle_t handle, elementNode* root, c bool isWildcard = false; RBUSLOG_DEBUG("Request to retrieve element [%s]", elmentName); - LOCK(); + if(currentNode == NULL) { return NULL; } - + LOCK(); name = strdup(elmentName); - nextNode = currentNode->child; /*TODO if name is a table row with an alias containing a dot, this will break (e.g. "Foo.[alias.1]")*/ @@ -1024,6 +1020,7 @@ elementNode* instantiateTableRow(elementNode* tableNode, uint32_t instNum, char if(!rowTemplate) { + UNLOCK(); assert(false); RBUSLOG_ERROR("ERROR: row template not found for table %s", tableNode->fullName); return NULL; diff --git a/src/rtmessage/rtThreadPool.c b/src/rtmessage/rtThreadPool.c index 79d5502e..8a9785a5 100644 --- a/src/rtmessage/rtThreadPool.c +++ b/src/rtmessage/rtThreadPool.c @@ -304,7 +304,10 @@ rtError rtThreadPool_RunTask(rtThreadPool pool, rtThreadPoolFunc func, void* use { task = rt_try_malloc(sizeof(struct _rtThreadTask)); if(!task) - return rtErrorFromErrno(ENOMEM); + { + pthread_mutex_unlock(&pool->poolLock); + return rtErrorFromErrno(ENOMEM); + } rtLog_Debug("taskList data null so alloc new %p", (void*)task); rtListItem_SetData(item, task); } @@ -321,7 +324,10 @@ rtError rtThreadPool_RunTask(rtThreadPool pool, rtThreadPoolFunc func, void* use { rtLog_Debug("%s creating new thread", __FUNCTION__); if((err = rtThreadPool_CreateWorkerThread(pool)) != RT_OK) - return err; + { + pthread_mutex_unlock(&pool->poolLock); + return err; + } if(pool->threadCount == pool->maxThreadCount - 1) rtLog_Debug("%s reached max thread count %zu", __FUNCTION__, pool->maxThreadCount); }