Prevent deadlock on thread creation error

This commit is contained in:
z3APA3A 2017-09-25 17:14:13 +03:00
parent 2554f06759
commit 984efe193b

View File

@ -774,6 +774,7 @@ int MODULEMAINFUNC (int argc, char** argv){
} }
#endif #endif
newparam->prev = newparam->next = NULL; newparam->prev = newparam->next = NULL;
error = 0;
pthread_mutex_lock(&srv.counter_mutex); pthread_mutex_lock(&srv.counter_mutex);
if(!srv.child){ if(!srv.child){
srv.child = newparam; srv.child = newparam;
@ -796,7 +797,7 @@ int MODULEMAINFUNC (int argc, char** argv){
else { else {
sprintf((char *)buf, "_beginthreadex(): %s", _strerror(NULL)); sprintf((char *)buf, "_beginthreadex(): %s", _strerror(NULL));
if(!srv.silent)(*srv.logfunc)(&defparam, buf); if(!srv.silent)(*srv.logfunc)(&defparam, buf);
freeparam(newparam); error = 1;
} }
#else #else
@ -805,13 +806,14 @@ int MODULEMAINFUNC (int argc, char** argv){
if(error){ if(error){
sprintf((char *)buf, "pthread_create(): %s", strerror(error)); sprintf((char *)buf, "pthread_create(): %s", strerror(error));
if(!srv.silent)(*srv.logfunc)(&defparam, buf); if(!srv.silent)(*srv.logfunc)(&defparam, buf);
freeparam(newparam);
} }
else { else {
newparam->threadid = (unsigned)thread; newparam->threadid = (unsigned)thread;
} }
#endif #endif
pthread_mutex_unlock(&srv.counter_mutex); pthread_mutex_unlock(&srv.counter_mutex);
if(error) freeparam(newparam);
memset(&defparam.sincl, 0, sizeof(defparam.sincl)); memset(&defparam.sincl, 0, sizeof(defparam.sincl));
memset(&defparam.sincr, 0, sizeof(defparam.sincr)); memset(&defparam.sincr, 0, sizeof(defparam.sincr));
if(isudp) while(!srv.fds.events)usleep(SLEEPTIME); if(isudp) while(!srv.fds.events)usleep(SLEEPTIME);