diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index f313b2dd0..5d22da1ac 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -230,6 +230,12 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, while (Token::Match(varTok, "%name% ::|. %name% !!(")) varTok = varTok->tokAt(2); + const Token *ftok = tok; + if (ftok->str() == "::") + ftok = ftok->next(); + while (Token::Match(ftok, "%name% :: %name%")) + ftok = ftok->tokAt(2); + // assignment.. if (Token::Match(varTok, "%var% =")) { // taking address of another variable.. @@ -444,14 +450,14 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, } // Function call.. - else if (Token::Match(tok, "%type% (")) { - const Library::AllocFunc* af = _settings->library.dealloc(tok); + else if (Token::Match(ftok, "%type% (")) { + const Library::AllocFunc* af = _settings->library.dealloc(ftok); VarInfo::AllocInfo allocation(af ? af->groupId : 0, VarInfo::DEALLOC); if (allocation.type == 0) allocation.status = VarInfo::NOALLOC; - functionCall(tok, varInfo, allocation, af); + functionCall(ftok, varInfo, allocation, af); - tok = tok->next()->link(); + tok = ftok->next()->link(); // Handle scopes that might be noreturn if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) { diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 0f17a4bee..5af8f1238 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -71,6 +71,7 @@ private: // exit TEST_CASE(exit1); TEST_CASE(exit2); + TEST_CASE(exit3); // goto TEST_CASE(goto1); @@ -849,6 +850,28 @@ private: errout.str()); } + void exit3() { + check("void f() {\n" + " char *p = malloc(100);\n" + " if (x) {\n" + " free(p);\n" + " ::exit(0);\n" + " }" + " free(p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " char *p = malloc(100);\n" + " if (x) {\n" + " free(p);\n" + " std::exit(0);\n" + " }" + " free(p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void goto1() { check("static void f() {\n" " int err = -ENOMEM;\n"