Fixed #3866 (false positive: memory leak (UNLIKELY))

This commit is contained in:
Daniel Marjamäki 2012-06-17 07:54:24 +02:00
parent 2481b80875
commit 62f92fe253
2 changed files with 12 additions and 1 deletions

View File

@ -302,8 +302,11 @@ 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());
} else if (Token::Match(tok->next(), "( %var% ( ! %var% ) )|&&")) {
varInfo1.erase(tok->tokAt(5)->varId());
}
checkScope(tok2->next(), &varInfo1, notzero); checkScope(tok2->next(), &varInfo1, notzero);
tok2 = tok2->linkAt(1); tok2 = tok2->linkAt(1);

View File

@ -299,6 +299,14 @@ private:
" free(p);\n" " free(p);\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #3866 - UNLIKELY
check("void f() {\n"
" char *p = malloc(10);\n"
" if (UNLIKELY(!p)) { return; }\n"
" free(p);\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void ifelse4() { void ifelse4() {