Memory Leak: Stronger checking. Ignore 'if use ;' and 'if dealloc;'. A leak could occur if it's not executed.
This commit is contained in:
parent
ef9f472188
commit
c2ea705fd7
|
@ -517,6 +517,14 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete "if dealloc ;" and "if use ;" that is not followed by an else..
|
||||
if ((Match(tok2, "[;{}] if dealloc ;") || Match(tok2, "[;{}] if use ;")) &&
|
||||
!Match(Tokenizer::gettok(tok2,4), "else"))
|
||||
{
|
||||
erase(tok2->next, Tokenizer::gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete if block: "alloc; if return use ;"
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(Tokenizer::gettok(tok2,6),"else"))
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
_FuncName = FuncName;
|
||||
}
|
||||
|
||||
const unsigned int file_id() const { return _FileId; }
|
||||
unsigned int file_id() const { return _FileId; }
|
||||
const std::string &name() const { return _FuncName; }
|
||||
};
|
||||
|
||||
|
|
|
@ -63,7 +63,9 @@ private:
|
|||
TEST_CASE( simple5 );
|
||||
TEST_CASE( simple6 );
|
||||
TEST_CASE( simple7 );
|
||||
TEST_CASE( simple8 );
|
||||
TEST_CASE( simple8 );
|
||||
|
||||
TEST_CASE( use1 );
|
||||
|
||||
TEST_CASE( ifelse1 );
|
||||
TEST_CASE( ifelse2 );
|
||||
|
@ -191,6 +193,21 @@ private:
|
|||
|
||||
|
||||
|
||||
|
||||
void use1()
|
||||
{
|
||||
check( "void foo()\n"
|
||||
"{\n"
|
||||
" char *str = strdup(\"abc\");\n"
|
||||
" if (somecondition)\n"
|
||||
" DeleteString(str);\n"
|
||||
"}\n" );
|
||||
|
||||
ASSERT_EQUALS( std::string("[test.cpp:6]: Memory leak: str\n"), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue