Fixed #3851 (False positive memory leak (condition))

This commit is contained in:
Daniel Marjamäki 2012-05-29 21:10:19 +02:00
parent da5278f90c
commit 8d0f315097
2 changed files with 11 additions and 1 deletions

View File

@ -292,7 +292,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
varInfo2.erase(tok->tokAt(2)->varId()); varInfo2.erase(tok->tokAt(2)->varId());
if (notzero.find(tok->tokAt(2)->varId()) != notzero.end()) if (notzero.find(tok->tokAt(2)->varId()) != notzero.end())
varInfo2.clear(); varInfo2.clear();
} else if (Token::Match(tok->next(), "( ! %var% )")) } else if (Token::Match(tok->next(), "( ! %var% )|&&"))
varInfo1.erase(tok->tokAt(3)->varId()); varInfo1.erase(tok->tokAt(3)->varId());
checkScope(tok2->next(), &varInfo1, notzero); checkScope(tok2->next(), &varInfo1, notzero);

View File

@ -62,6 +62,7 @@ private:
TEST_CASE(ifelse2); TEST_CASE(ifelse2);
TEST_CASE(ifelse3); TEST_CASE(ifelse3);
TEST_CASE(ifelse4); TEST_CASE(ifelse4);
TEST_CASE(ifelse5);
// switch // switch
TEST_CASE(switch1); TEST_CASE(switch1);
@ -313,6 +314,15 @@ private:
ASSERT_EQUALS("", errout.str()); 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() { void switch1() {
check("void f() {\n" check("void f() {\n"
" char *p = 0;\n" " char *p = 0;\n"