added checks for result of pthread_create (issue #126)

This commit is contained in:
csoler 2015-10-20 18:39:32 -04:00
parent f49f7ac763
commit 6398ed2c17
4 changed files with 36 additions and 15 deletions

View file

@ -103,10 +103,18 @@ bool upnphandler::background_setup_upnp(bool start, bool stop)
data->start = start;
data->stop = stop;
pthread_create(&tid, 0, &doSetupUPnP, (void *) data);
if(! pthread_create(&tid, 0, &doSetupUPnP, (void *) data))
{
pthread_detach(tid); /* so memory is reclaimed in linux */
return true;
}
else
{
delete data ;
std::cerr << "(EE) Could not start background upnp thread!" << std::endl;
return false ;
}
}
bool upnphandler::start_upnp()

View file

@ -236,10 +236,17 @@ bool upnphandler::background_setup_upnp(bool start, bool stop)
data->start = start;
data->stop = stop;
pthread_create(&tid, 0, &doSetupUPnP, (void *) data);
pthread_detach(tid); /* so memory is reclaimed in linux */
return true;
if(!pthread_create(&tid, 0, &doSetupUPnP, (void *) data))
{
pthread_detach(tid); /* so memory is reclaimed in linux */
return true;
}
else
{
delete data ;
std::cerr << "(EE) Failed to start upnp thread." << std::endl;
return false ;
}
}
bool upnphandler::start_upnp()