Fixed #7738 (False positive deallocret - delete and return NULL pointer)

This commit is contained in:
Daniel Marjamäki 2017-04-24 22:05:16 +02:00
parent 37fd60e879
commit 140e086206
2 changed files with 14 additions and 1 deletions

View File

@ -483,7 +483,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
tok = tok->next();
while (Token::Match(tok, "%name% ::|."))
tok = tok->tokAt(2);
if (tok->varId() && tok->strAt(1) != "[") {
bool isnull = tok->hasKnownIntValue() && tok->values().front().intvalue == 0;
if (!isnull && tok->varId() && tok->strAt(1) != "[") {
VarInfo::AllocInfo allocation(arrayDelete ? -2 : -1, VarInfo::DEALLOC);
changeAllocStatus(varInfo, allocation, tok, tok);
}

View File

@ -310,6 +310,18 @@ private:
" return p;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(char *p) {\n"
" if (!p) delete p;\n"
" return p;\n"
"}", true);
ASSERT_EQUALS("", errout.str());
check("void f(char *p) {\n"
" if (!p) delete [] p;\n"
" return p;\n"
"}", true);
ASSERT_EQUALS("", errout.str());
}
void deallocuse5() { // #4018