Fixed #7191 (false positive memleak on in-place new)
This commit is contained in:
parent
549fec1628
commit
65297ce285
|
@ -290,7 +290,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
alloctype[varTok->varId()].type = f->groupId;
|
||||
alloctype[varTok->varId()].status = VarInfo::ALLOC;
|
||||
}
|
||||
} else if (_tokenizer->isCPP() && varTok->strAt(2) == "new") {
|
||||
} else if (_tokenizer->isCPP() && Token::Match(varTok->tokAt(2), "new !!(")) {
|
||||
const Token* tok2 = varTok->tokAt(2)->astOperand1();
|
||||
bool arrayNew = (tok2 && (tok2->str() == "[" || (tok2->str() == "(" && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
|
||||
alloctype[varTok->varId()].type = arrayNew ? -2 : -1;
|
||||
|
|
|
@ -1066,6 +1066,11 @@ private:
|
|||
" free(cPtr);\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Mismatching allocation and deallocation: cPtr\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char *cPtr = new (buf) char[100];\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void return1() {
|
||||
|
|
Loading…
Reference in New Issue