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()) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue