diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 5d75f549c..cab57af8f 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 6c5446a16..5e67dfbd5 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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"