Fixed #1428 (False positive: (possible error) Memory leak when memory deleted in destructor)
This commit is contained in:
parent
9c2248254e
commit
54c5d53eac
|
@ -2338,8 +2338,8 @@ void CheckMemoryLeakInClass::variable(const std::string &classname, const Token
|
||||||
const Token *functionToken = _tokenizer->findClassFunction(_tokenizer->tokens(), classname.c_str(), "~| %var%", indent_);
|
const Token *functionToken = _tokenizer->findClassFunction(_tokenizer->tokens(), classname.c_str(), "~| %var%", indent_);
|
||||||
while (functionToken)
|
while (functionToken)
|
||||||
{
|
{
|
||||||
const bool constructor(Token::Match(functionToken, (classname + " :: " + classname + " (").c_str()));
|
const bool constructor(Token::Match(functionToken, (classname + " (").c_str()) || Token::Match(functionToken, (classname + " :: " + classname + " (").c_str()));
|
||||||
const bool destructor(functionToken->tokAt(2)->str() == "~");
|
const bool destructor(functionToken->str() == "~" || functionToken->tokAt(2)->str() == "~");
|
||||||
|
|
||||||
unsigned int indent = 0;
|
unsigned int indent = 0;
|
||||||
bool initlist = false;
|
bool initlist = false;
|
||||||
|
|
|
@ -2738,6 +2738,7 @@ private:
|
||||||
TEST_CASE(class12);
|
TEST_CASE(class12);
|
||||||
TEST_CASE(class13);
|
TEST_CASE(class13);
|
||||||
TEST_CASE(class14);
|
TEST_CASE(class14);
|
||||||
|
TEST_CASE(class15);
|
||||||
|
|
||||||
TEST_CASE(staticvar);
|
TEST_CASE(staticvar);
|
||||||
|
|
||||||
|
@ -3020,6 +3021,20 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (possible error) Memory leak: A::p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (possible error) Memory leak: A::p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void class15()
|
||||||
|
{
|
||||||
|
check("class A\n"
|
||||||
|
"{\n"
|
||||||
|
" int *p;\n"
|
||||||
|
"public:\n"
|
||||||
|
" A();\n"
|
||||||
|
" ~A() { delete [] p; }\n"
|
||||||
|
"};\n"
|
||||||
|
"A::A()\n"
|
||||||
|
"{ p = new int[10]; }", true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void staticvar()
|
void staticvar()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue