Fixed #2790 (Incorrect allocation mismatch error)

This commit is contained in:
Daniel Marjamäki 2011-05-19 19:41:18 +02:00
parent 21a2a91b3c
commit 52499ca8f8
2 changed files with 15 additions and 0 deletions

View File

@ -1047,6 +1047,9 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
alloc = No;
}
}
if (alloc == No && alloctype == No)
alloctype = CheckMemoryLeak::New;
}
if (alloc != No)

View File

@ -208,6 +208,7 @@ private:
TEST_CASE(mismatch2);
TEST_CASE(mismatch3);
TEST_CASE(mismatch4);
TEST_CASE(mismatch5);
TEST_CASE(mismatchSize);
@ -1425,6 +1426,17 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n", errout.str());
}
void mismatch5()
{
check("void f() {\n"
" C *c = new C;\n"
" delete c;\n"
" c = new C[2];\n"
" delete [] c;\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
}
void mismatchSize()
{
check("void f(char *buf)\n"