Fixed #4034 (false positive:(error) Dereferencing 'cfileP' after it is deallocated / released)
This commit is contained in:
parent
6fc7f0227c
commit
9fe9944adb
|
@ -240,7 +240,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
if (tok->varId() > 0) {
|
||||
const std::map<unsigned int, std::string>::iterator var = alloctype.find(tok->varId());
|
||||
if (var != alloctype.end()) {
|
||||
if (var->second == "dealloc" && !Token::Match(tok->previous(), "[;{},] %var% =")) {
|
||||
if (var->second == "dealloc" && !Token::Match(tok->previous(), "[;{},=] %var% =")) {
|
||||
deallocUseError(tok, tok->str());
|
||||
} else if (Token::simpleMatch(tok->tokAt(-2), "= &")) {
|
||||
varInfo->erase(tok->varId());
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
TEST_CASE(deallocuse3);
|
||||
TEST_CASE(deallocuse4);
|
||||
TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;
|
||||
TEST_CASE(deallocuse6); // #4034: FP. x = p = f();
|
||||
|
||||
TEST_CASE(doublefree1);
|
||||
TEST_CASE(doublefree2);
|
||||
|
@ -264,6 +265,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void deallocuse6() { // #4034
|
||||
check("void f(char *p) {\n"
|
||||
" free(p);\n"
|
||||
" x = p = foo();\n" // <- p is not dereferenced
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void doublefree1() { // #3895
|
||||
check("void f(char *p) {\n"
|
||||
" if (x)\n"
|
||||
|
|
Loading…
Reference in New Issue