TestLocalLeaks: going out of scope
This commit is contained in:
parent
64261e6909
commit
368df4c083
|
@ -2586,7 +2586,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ret(const std::list<ExecutionPath *> &checks, const Token *tok)
|
static void ret(const std::list<ExecutionPath *> &checks, const Token *tok, bool &foundError)
|
||||||
{
|
{
|
||||||
std::list<ExecutionPath *>::const_iterator it;
|
std::list<ExecutionPath *>::const_iterator it;
|
||||||
for (it = checks.begin(); it != checks.end(); ++it)
|
for (it = checks.begin(); it != checks.end(); ++it)
|
||||||
|
@ -2595,11 +2595,12 @@ private:
|
||||||
if (C && C->allocated)
|
if (C && C->allocated)
|
||||||
{
|
{
|
||||||
C->ownerCheck->memleakError(tok, C->varname, false);
|
C->ownerCheck->memleakError(tok, C->varname, false);
|
||||||
|
foundError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *parse(const Token &tok, bool &, std::list<ExecutionPath *> &checks) const
|
const Token *parse(const Token &tok, bool &foundError, std::list<ExecutionPath *> &checks) const
|
||||||
{
|
{
|
||||||
//std::cout << "CheckLocalLeaks::parse " << tok.str() << std::endl;
|
//std::cout << "CheckLocalLeaks::parse " << tok.str() << std::endl;
|
||||||
//printOut(checks);
|
//printOut(checks);
|
||||||
|
@ -2640,11 +2641,19 @@ private:
|
||||||
|
|
||||||
if (tok.str() == "return")
|
if (tok.str() == "return")
|
||||||
{
|
{
|
||||||
ret(checks, &tok);
|
ret(checks, &tok, foundError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tok;
|
return &tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** going out of scope - all execution paths end */
|
||||||
|
static void end(const std::list<ExecutionPath *> &checks, const Token *tok)
|
||||||
|
{
|
||||||
|
bool foundError = false;
|
||||||
|
ret(checks, tok, foundError);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2667,6 +2676,7 @@ void CheckMemoryLeakInFunction::localleaks()
|
||||||
std::list<ExecutionPath *> checks;
|
std::list<ExecutionPath *> checks;
|
||||||
checks.push_back(new CheckLocalLeaks(this));
|
checks.push_back(new CheckLocalLeaks(this));
|
||||||
checkExecutionPaths(tok->next(), checks);
|
checkExecutionPaths(tok->next(), checks);
|
||||||
|
CheckLocalLeaks::end(checks, tok->link());
|
||||||
while (!checks.empty())
|
while (!checks.empty())
|
||||||
{
|
{
|
||||||
delete checks.back();
|
delete checks.back();
|
||||||
|
|
|
@ -65,7 +65,6 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *p = new char[100];\n"
|
" char *p = new char[100];\n"
|
||||||
" return;\n"
|
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -76,7 +75,6 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *p = new char[100];\n"
|
" char *p = new char[100];\n"
|
||||||
" delete [] p;\n"
|
" delete [] p;\n"
|
||||||
" return;\n"
|
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue