CheckMemoryLeak: Correctly detect new char[...]() as array allocation (#7164)

This commit is contained in:
PKEuS 2015-11-27 11:04:18 +01:00
parent a6206ae727
commit 0ba3d25917
2 changed files with 7 additions and 1 deletions

View File

@ -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;
}

View File

@ -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() {