Doublefree: Fixed FP when exit() is called
This commit is contained in:
parent
5edb6092a1
commit
636a15ac55
|
@ -168,6 +168,14 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
if (tok->str() == "(" && tok->previous()->isName()) {
|
if (tok->str() == "(" && tok->previous()->isName()) {
|
||||||
functionCall(tok->previous(), varInfo, NOALLOC);
|
functionCall(tok->previous(), varInfo, NOALLOC);
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
|
||||||
|
if (Token::simpleMatch(tok,") ; }")) {
|
||||||
|
bool unknown = false;
|
||||||
|
const bool noreturn = _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown);
|
||||||
|
if (noreturn)
|
||||||
|
varInfo->clear();
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
TEST_CASE(doublefree1);
|
TEST_CASE(doublefree1);
|
||||||
TEST_CASE(doublefree2);
|
TEST_CASE(doublefree2);
|
||||||
TEST_CASE(doublefree3); // #4914
|
TEST_CASE(doublefree3); // #4914
|
||||||
|
TEST_CASE(doublefree4); // #5451 - FP when exit is called
|
||||||
|
|
||||||
// exit
|
// exit
|
||||||
TEST_CASE(exit1);
|
TEST_CASE(exit1);
|
||||||
|
@ -348,6 +349,17 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doublefree4() { // #5451 - exit
|
||||||
|
check("void foo(char *p) {\n"
|
||||||
|
" if (x) {\n"
|
||||||
|
" free(p)\n"
|
||||||
|
" exit(1);\n"
|
||||||
|
" }\n"
|
||||||
|
" free(p);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void exit1() {
|
void exit1() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
|
|
|
@ -160,7 +160,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
std::vector<std::string> testfiles;
|
std::vector<std::string> testfiles;
|
||||||
getCppFiles(testfiles, "test/");
|
getCppFiles(testfiles, "test/");
|
||||||
|
|
||||||
std::vector<std::string> toolsfiles;
|
std::vector<std::string> toolsfiles;
|
||||||
getCppFiles(toolsfiles, "tools/");
|
getCppFiles(toolsfiles, "tools/");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue