Skip to content
Snippets Groups Projects
Commit 15e40a45 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix potential deadlock in getnodedat(), observed on macOS

Upon any node.dab lock or read failure, this code would cause errormsg() which
would often/usually end up claling getnodedat() which would block forever trying
to acquire the ndoefile_mutex (introduced in commit b9633069, I'm not clear why).

Unlock/release the mutex *before* calling errormsg().
parent 27785543
No related branches found
No related tags found
No related merge requests found
Pipeline #7248 passed
...@@ -47,8 +47,8 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) ...@@ -47,8 +47,8 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit)
pthread_mutex_lock(&nodefile_mutex); pthread_mutex_lock(&nodefile_mutex);
if(nodefile==-1) { if(nodefile==-1) {
if((nodefile=nopen(str,O_RDWR|O_DENYNONE))==-1) { if((nodefile=nopen(str,O_RDWR|O_DENYNONE))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE);
pthread_mutex_unlock(&nodefile_mutex); pthread_mutex_unlock(&nodefile_mutex);
errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE);
return(errno); return(errno);
} }
} }
...@@ -77,11 +77,11 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) ...@@ -77,11 +77,11 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit)
} }
if(count==LOOP_NODEDAB) { if(count==LOOP_NODEDAB) {
errormsg(WHERE,rd==sizeof(node_t) ? ERR_LOCK : ERR_READ,"node.dab",number+1);
if(nodefile!=-1) if(nodefile!=-1)
close(nodefile); close(nodefile);
nodefile=-1; nodefile=-1;
pthread_mutex_unlock(&nodefile_mutex); pthread_mutex_unlock(&nodefile_mutex);
errormsg(WHERE,rd==sizeof(node_t) ? ERR_LOCK : ERR_READ,"node.dab",number+1);
return(-2); return(-2);
} }
pthread_mutex_unlock(&nodefile_mutex); pthread_mutex_unlock(&nodefile_mutex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment