Memory leaks: better handling of 'return strcmp(..' etc
This commit is contained in:
parent
81c058f2be
commit
eedb5e383e
|
@ -28,6 +28,7 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -1274,6 +1275,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
{
|
||||
bool use = false;
|
||||
|
||||
std::stack<const Token *> f;
|
||||
|
||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == ";")
|
||||
|
@ -1282,6 +1285,11 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
break;
|
||||
}
|
||||
|
||||
if (tok2->str() == "(")
|
||||
f.push(tok2->previous());
|
||||
else if (tok2->str() == ")")
|
||||
f.pop();
|
||||
|
||||
if (tok2->varId() == varid)
|
||||
{
|
||||
// Read data..
|
||||
|
@ -1289,7 +1297,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
Token::simpleMatch(tok2->next(), "["))
|
||||
{
|
||||
}
|
||||
else
|
||||
else if (f.empty() || !test_white_list(f.top()->str()))
|
||||
{
|
||||
use = true;
|
||||
}
|
||||
|
|
|
@ -456,6 +456,7 @@ private:
|
|||
// alloc; return;
|
||||
ASSERT_EQUALS(";;alloc;return;", getcode("char *s = new char[100]; return 0;", "s"));
|
||||
ASSERT_EQUALS(";;alloc;return;", getcode("char *s = new char[100]; return s[0];", "s"));
|
||||
ASSERT_EQUALS(";;alloc;return;", getcode("char *s = new char[100]; return strcmp(s,x);", "s"));
|
||||
|
||||
// lock/unlock..
|
||||
ASSERT_EQUALS(";;alloc;", getcode("int a; __cppcheck_lock();", ""));
|
||||
|
@ -1392,7 +1393,6 @@ private:
|
|||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
void func3()
|
||||
{
|
||||
check("static void foo(const char *str)\n"
|
||||
|
|
Loading…
Reference in New Issue