CheckMemoryLeak: Correctly detect new char[...]() as array allocation (#7164)
This commit is contained in:
parent
a6206ae727
commit
0ba3d25917
|
@ -123,7 +123,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
|||
return Malloc;
|
||||
|
||||
if (tokenizer->isCPP() && tok2->str() == "new") {
|
||||
if (tok2->astOperand1() && tok2->astOperand1()->str() == "[")
|
||||
if (tok2->astOperand1() && (tok2->astOperand1()->str() == "[" || (tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->str() == "[")))
|
||||
return NewArray;
|
||||
return New;
|
||||
}
|
||||
|
|
|
@ -1420,6 +1420,12 @@ private:
|
|||
" free(a);\n"
|
||||
"}\n", false, false, true);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: a\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char* str = new char[42]();\n"
|
||||
" delete[] str;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void mismatch2() {
|
||||
|
|
Loading…
Reference in New Issue