Doublefree: Fixed FP when exit() is called

This commit is contained in:
Daniel Marjamäki 2014-05-04 12:02:55 +02:00
parent 5edb6092a1
commit 636a15ac55
3 changed files with 21 additions and 1 deletions

View File

@ -168,6 +168,14 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (tok->str() == "(" && tok->previous()->isName()) {
functionCall(tok->previous(), varInfo, NOALLOC);
tok = tok->link();
if (Token::simpleMatch(tok,") ; }")) {
bool unknown = false;
const bool noreturn = _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown);
if (noreturn)
varInfo->clear();
}
continue;
}

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
TEST_CASE(doublefree3); // #4914
TEST_CASE(doublefree4); // #5451 - FP when exit is called
// exit
TEST_CASE(exit1);
@ -348,6 +349,17 @@ private:
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() {
check("void f() {\n"
" char *p = malloc(10);\n"