Fixed #3024 (False positive: memory leak for 'rc.bitmap' when rc is added to linux kernel list)

This commit is contained in:
Daniel Marjamäki 2011-08-20 09:17:34 +02:00
parent fe78e28d70
commit dd09b24208
2 changed files with 20 additions and 0 deletions

View File

@ -3199,6 +3199,14 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
deallocated = true; deallocated = true;
break; break;
} }
// Linux kernel list
if (Token::Match(tok4, "[(,] & %varid% . %var% [,)]", structid))
{
/** @todo check if the function deallocates the memory */
deallocated = true;
break;
}
} }
if (deallocated) if (deallocated)

View File

@ -4982,6 +4982,7 @@ private:
TEST_CASE(function1); // Deallocating in function TEST_CASE(function1); // Deallocating in function
TEST_CASE(function2); // #2848: Taking address in function TEST_CASE(function2); // #2848: Taking address in function
TEST_CASE(function3); // #3024: kernel list
// Handle if-else // Handle if-else
TEST_CASE(ifelse); TEST_CASE(ifelse);
@ -5176,6 +5177,17 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
// #3024: kernel list
void function3()
{
check("void f() {\n"
" struct ABC *abc = kmalloc(100);\n"
" abc.a = (char *) kmalloc(10);\n"
" list_add_tail(&abc->list, head);\n"
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
}
void ifelse() void ifelse()
{ {
check("static void foo()\n" check("static void foo()\n"