id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 4368,boost::recursive_mutex constructor potential resource leak,Steve Hawkes ,Anthony Williams,"When running the Klocwork static code analysis tool on some code that uses Boost.Thread, Klocwork reported the following potential issue (note that this is for boost 1_36_0, but the latest trunk code appears to have the same issue): ---- boost-1_36/boost/thread/pthread/recursive_mutex.hpp: 50[[BR]] Resource acquired to 'attr' at line 42 may be lost here. Also there is one similar error on line 56.[[BR]] recursive_mutex.hpp#1:42: Resource is acquired: 'attr' is accessed via 1 argument of the call to function 'pthread_mutexattr_init'[[BR]] recursive_mutex.hpp#1:43: init_attr_res is false[[BR]] recursive_mutex.hpp#1:47: 'attr' might be changed[[BR]] recursive_mutex.hpp#1:48: set_attr_res is true[[BR]] recursive_mutex.hpp#1:50: Resource is lost: 'attr' ---- I'm not absolutely certain this is the issue Klocwork is attempting to report, but in the boost/thread/pthread/recursive_mutex.hpp header file the mutex attribute object is not destroyed if an exception is thrown due to pthread_mutexattr_settype() failure. I see that pthread_mutexattr_destroy() has been added since 1_36_0 for the case where pthread_mutex_init() fails. A similar call is needed if pthread_mutexattr_settype() fails. {{{ recursive_mutex() { #ifdef BOOST_PTHREAD_HAS_MUTEXATTR_SETTYPE pthread_mutexattr_t attr; int const init_attr_res=pthread_mutexattr_init(&attr); if(init_attr_res) { boost::throw_exception(thread_resource_error()); } int const set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); if(set_attr_res) { // Shouldn't the following line be added here? // BOOST_VERIFY(!pthread_mutexattr_destroy(&attr)); boost::throw_exception(thread_resource_error()); } int const res=pthread_mutex_init(&m,&attr); if(res) { BOOST_VERIFY(!pthread_mutexattr_destroy(&attr)); boost::throw_exception(thread_resource_error()); } BOOST_VERIFY(!pthread_mutexattr_destroy(&attr)); }}} ",Bugs,closed,Boost 1.44.0,thread,Boost Development Trunk,Problem,fixed,recursive_mutex,