Fixed #1286 (Memory leak not detected)
This commit is contained in:
parent
15b4abd6d3
commit
9d11492845
|
@ -2257,10 +2257,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
|
|||
// Go into class.
|
||||
while (tok1 && tok1->str() != "{")
|
||||
tok1 = tok1->next();
|
||||
if (tok1)
|
||||
tok1 = tok1->next();
|
||||
tok1 = tok1 ? tok1->next() : 0;
|
||||
|
||||
int indentlevel = 0;
|
||||
unsigned int indentlevel = 0;
|
||||
for (const Token *tok = tok1; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "{")
|
||||
|
@ -2268,9 +2267,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
|
|||
|
||||
else if (tok->str() == "}")
|
||||
{
|
||||
--indentlevel;
|
||||
if (indentlevel < 0)
|
||||
if (indentlevel == 0)
|
||||
return;
|
||||
--indentlevel;
|
||||
}
|
||||
|
||||
// Only parse this particular class.. not subclasses
|
||||
|
@ -2292,17 +2291,14 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
|
|||
}
|
||||
|
||||
// Declaring member variable.. check allocations and deallocations
|
||||
if (Token::Match(tok->next(), "%type% * %var% ;"))
|
||||
if (Token::Match(tok->previous(), ";|{|}|private:|protected:|public: %type% * %var% ;"))
|
||||
{
|
||||
// No false positives for auto deallocated classes..
|
||||
if (_settings->isAutoDealloc(tok->strAt(1)))
|
||||
if (_settings->isAutoDealloc(tok->str().c_str()))
|
||||
continue;
|
||||
|
||||
if (tok->isName() || Token::Match(tok, "[;}]"))
|
||||
{
|
||||
if (_settings->_showAll || !isclass(_tokenizer, tok->tokAt(1)))
|
||||
variable(classname.back(), tok->tokAt(3));
|
||||
}
|
||||
if (_settings->_showAll || !isclass(_tokenizer, tok))
|
||||
variable(classname.back(), tok->tokAt(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2721,6 +2721,7 @@ private:
|
|||
TEST_CASE(class11);
|
||||
TEST_CASE(class12);
|
||||
TEST_CASE(class13);
|
||||
TEST_CASE(class14);
|
||||
|
||||
TEST_CASE(staticvar);
|
||||
|
||||
|
@ -2989,6 +2990,20 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void class14()
|
||||
{
|
||||
check("class A\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
"public:\n"
|
||||
" void init();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void A::init()\n"
|
||||
"{ p = new int[10]; }\n", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (possible error) Memory leak: A::p\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void staticvar()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue