CheckMemoryLeak: Added testcase (false positive from linux kernel)
This commit is contained in:
parent
0b8f646e0b
commit
6bdb2ff0dc
|
@ -587,7 +587,8 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
}
|
||||
|
||||
// if else switch
|
||||
if ( Match(tok, "if ( %var1% )", varnames) )
|
||||
if ( Match(tok, "if ( %var1% )", varnames) ||
|
||||
Match(tok, "if ( %var1% != NULL )", varnames) )
|
||||
{
|
||||
addtoken("if(var)");
|
||||
}
|
||||
|
@ -657,7 +658,7 @@ static void erase(TOKEN *begin, const TOKEN *end)
|
|||
while ( begin->next && begin->next != end )
|
||||
{
|
||||
TOKEN *next = begin->next;
|
||||
begin->next = begin->next->next;
|
||||
begin->next = begin->next->next;
|
||||
free(next->str);
|
||||
delete next;
|
||||
}
|
||||
|
@ -743,21 +744,21 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
erase(tok2, gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete if block: "alloc; if return use ;"
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(gettok(tok2,6),"else"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,5));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// "[;{}] if alloc ; else return ;" => "[;{}] alloc ;"
|
||||
if (Match(tok2,"[;{}] if alloc ; else return ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,2)); // Remove "if"
|
||||
erase(tok2->next, gettok(tok2,5)); // Remove "; else return"
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete if block: "alloc; if return use ;"
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(gettok(tok2,6),"else"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,5));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// "[;{}] if alloc ; else return ;" => "[;{}] alloc ;"
|
||||
if (Match(tok2,"[;{}] if alloc ; else return ;"))
|
||||
{
|
||||
erase(tok2, gettok(tok2,2)); // Remove "if"
|
||||
erase(tok2->next, gettok(tok2,5)); // Remove "; else return"
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete "loop ;"
|
||||
if ( Match(tok2->next, "loop ;") )
|
||||
|
@ -780,8 +781,8 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( findmatch(tok, "alloc ; if continue ;") )
|
||||
{
|
||||
|
|
41
tests.cpp
41
tests.cpp
|
@ -611,10 +611,10 @@ static void memleak_in_function()
|
|||
" return;\n"
|
||||
" }\n"
|
||||
" delete [] str;\n"
|
||||
"}\n";
|
||||
"}\n";
|
||||
ShowAll = false;
|
||||
check( CheckMemoryLeak, __LINE__, code, "" );
|
||||
ShowAll = true;
|
||||
ShowAll = true;
|
||||
|
||||
code = "static char *f()\n"
|
||||
"{\n"
|
||||
|
@ -638,7 +638,7 @@ static void memleak_in_function()
|
|||
" return s;\n"
|
||||
"}\n";
|
||||
check_( CheckMemoryLeak, __LINE__, code, "" );
|
||||
|
||||
|
||||
|
||||
code = "static char *f()\n"
|
||||
"{\n"
|
||||
|
@ -648,10 +648,10 @@ static void memleak_in_function()
|
|||
" return s;\n"
|
||||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n";
|
||||
"}\n";
|
||||
ShowAll = false;
|
||||
check( CheckMemoryLeak, __LINE__, code, "" );
|
||||
ShowAll = true;
|
||||
ShowAll = true;
|
||||
|
||||
|
||||
|
||||
|
@ -807,21 +807,22 @@ static void memleak_in_function()
|
|||
*/
|
||||
|
||||
|
||||
|
||||
code = "static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)\n"
|
||||
"{\n"
|
||||
" struct fib6_table *table;\n"
|
||||
"\n"
|
||||
" table = kzalloc(sizeof(*table), GFP_ATOMIC);\n"
|
||||
" if (table != NULL) {\n"
|
||||
" table->tb6_id = id;\n"
|
||||
" table->tb6_root.leaf = net->ipv6.ip6_null_entry;\n"
|
||||
" table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return table;\n"
|
||||
"}\n";
|
||||
check_( CheckMemoryLeak, __LINE__, code, "" );
|
||||
code = "static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)\n"
|
||||
"{\n"
|
||||
" struct fib6_table *table;\n"
|
||||
"\n"
|
||||
" table = kzalloc(sizeof(*table), GFP_ATOMIC);\n"
|
||||
" if (table != NULL) {\n"
|
||||
" table->tb6_id = id;\n"
|
||||
" table->tb6_root.leaf = net->ipv6.ip6_null_entry;\n"
|
||||
" table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return table;\n"
|
||||
"}\n";
|
||||
ShowAll = false;
|
||||
check( CheckMemoryLeak, __LINE__, code, "" );
|
||||
ShowAll = true;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue