Fixed #3851 (False positive memory leak (condition))
This commit is contained in:
parent
da5278f90c
commit
8d0f315097
|
@ -292,7 +292,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
varInfo2.erase(tok->tokAt(2)->varId());
|
||||
if (notzero.find(tok->tokAt(2)->varId()) != notzero.end())
|
||||
varInfo2.clear();
|
||||
} else if (Token::Match(tok->next(), "( ! %var% )"))
|
||||
} else if (Token::Match(tok->next(), "( ! %var% )|&&"))
|
||||
varInfo1.erase(tok->tokAt(3)->varId());
|
||||
|
||||
checkScope(tok2->next(), &varInfo1, notzero);
|
||||
|
|
|
@ -62,6 +62,7 @@ private:
|
|||
TEST_CASE(ifelse2);
|
||||
TEST_CASE(ifelse3);
|
||||
TEST_CASE(ifelse4);
|
||||
TEST_CASE(ifelse5);
|
||||
|
||||
// switch
|
||||
TEST_CASE(switch1);
|
||||
|
@ -313,6 +314,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void ifelse5() {
|
||||
check("void f() {\n"
|
||||
" char *p = malloc(10);\n"
|
||||
" if (!p && x) { p = malloc(10); }\n"
|
||||
" free(p);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void switch1() {
|
||||
check("void f() {\n"
|
||||
" char *p = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue