Fixed false positive #6467
This commit is contained in:
parent
9ada111045
commit
71379616e7
|
@ -154,7 +154,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
if (tok->varId() > 0) {
|
if (tok->varId() > 0) {
|
||||||
const std::map<unsigned int, VarInfo::AllocInfo>::iterator var = alloctype.find(tok->varId());
|
const std::map<unsigned int, VarInfo::AllocInfo>::iterator var = alloctype.find(tok->varId());
|
||||||
if (var != alloctype.end()) {
|
if (var != alloctype.end()) {
|
||||||
if (var->second.status == VarInfo::DEALLOC && !Token::Match(tok->previous(), "[;{},=] %var% =")) {
|
if (var->second.status == VarInfo::DEALLOC && (!Token::Match(tok, "%var% =") || tok->strAt(-1) == "*")) {
|
||||||
deallocUseError(tok, tok->str());
|
deallocUseError(tok, tok->str());
|
||||||
} else if (Token::simpleMatch(tok->tokAt(-2), "= &")) {
|
} else if (Token::simpleMatch(tok->tokAt(-2), "= &")) {
|
||||||
varInfo->erase(tok->varId());
|
varInfo->erase(tok->varId());
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
TEST_CASE(deallocuse4);
|
TEST_CASE(deallocuse4);
|
||||||
TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;
|
TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0;
|
||||||
TEST_CASE(deallocuse6); // #4034: FP. x = p = f();
|
TEST_CASE(deallocuse6); // #4034: FP. x = p = f();
|
||||||
|
TEST_CASE(deallocuse7); // #6467
|
||||||
|
|
||||||
TEST_CASE(doublefree1);
|
TEST_CASE(doublefree1);
|
||||||
TEST_CASE(doublefree2);
|
TEST_CASE(doublefree2);
|
||||||
|
@ -315,6 +316,22 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deallocuse7() { // #6467
|
||||||
|
check("struct Foo { int* ptr; };\n"
|
||||||
|
"void f(Foo* foo) {\n"
|
||||||
|
" delete foo->ptr;\n"
|
||||||
|
" foo->ptr = new Foo; \n"
|
||||||
|
"}", true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct Foo { int* ptr; };\n"
|
||||||
|
"void f(Foo* foo) {\n"
|
||||||
|
" delete foo->ptr;\n"
|
||||||
|
" x = *foo->ptr; \n"
|
||||||
|
"}", true);
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void doublefree1() { // #3895
|
void doublefree1() { // #3895
|
||||||
check("void f(char *p) {\n"
|
check("void f(char *p) {\n"
|
||||||
" if (x)\n"
|
" if (x)\n"
|
||||||
|
|
Loading…
Reference in New Issue