Fixed crashes random crashes in multithreading caused by useless creation of CheckUnusedFunctions instance per thread.

This commit is contained in:
PKEuS 2014-04-13 11:51:29 +02:00
parent 73fc3d6a13
commit 9bfc2b618b
5 changed files with 22 additions and 7 deletions

View File

@ -27,6 +27,9 @@
// Register this check class
CheckUnusedFunctions CheckUnusedFunctions::instance;
//---------------------------------------------------------------------------
// FUNCTION USAGE - Check for unused functions etc

View File

@ -31,7 +31,7 @@
/** @brief Check for functions never called */
/// @{
class CPPCHECKLIB CheckUnusedFunctions: public Check {
class CPPCHECKLIB CheckUnusedFunctions : public Check {
public:
/** @brief This constructor is used when registering the CheckUnusedFunctions */
CheckUnusedFunctions() : Check(myName()) {
@ -49,6 +49,8 @@ public:
void check(ErrorLogger * const errorLogger);
static CheckUnusedFunctions instance;
private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {

View File

@ -282,7 +282,7 @@ void CppCheck::checkFunctionUsage()
if (_settings._errorsOnly == false)
_errorLogger.reportOut("Checking usage of global functions..");
_checkUnusedFunctions.check(this);
CheckUnusedFunctions::instance.check(this);
_settings._verbose = verbose_orig;
}
@ -359,7 +359,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
}
// call all "runChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated())
return;
@ -368,7 +368,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
}
if (_settings.isEnabled("unusedFunction") && _settings._jobs == 1)
_checkUnusedFunctions.parseTokens(_tokenizer, FileName, &_settings);
CheckUnusedFunctions::instance.parseTokens(_tokenizer, FileName, &_settings);
executeRules("normal", _tokenizer);
@ -382,7 +382,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
return;
// call all "runSimplifiedChecks" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
if (_settings.terminated())
return;
@ -638,7 +638,7 @@ void CppCheck::getErrorMessages()
tooManyConfigsError("",0U);
// call all "getErrorMessages" in all registered Check classes
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
(*it)->getErrorMessages(this, &_settings);
Tokenizer::getErrorMessages(this, &_settings);

View File

@ -194,7 +194,6 @@ private:
*/
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg);
CheckUnusedFunctions _checkUnusedFunctions;
ErrorLogger &_errorLogger;
/** @brief Current preprocessor configuration */

View File

@ -65,6 +65,7 @@ private:
void run() {
TEST_CASE(deadlock_with_many_errors);
TEST_CASE(many_threads);
TEST_CASE(no_errors_more_files);
TEST_CASE(no_errors_less_files);
TEST_CASE(no_errors_equal_amount_files);
@ -84,6 +85,16 @@ private:
check(2, 3, 3, oss.str());
}
void many_threads() {
std::ostringstream oss;
oss << "int main()\n"
<< "{\n";
oss << " char *a = malloc(10);\n";
oss << " return 0;\n"
<< "}";
check(20, 100, 100, oss.str());
}
void no_errors_more_files() {
std::ostringstream oss;
oss << "int main()\n"