Fixed #3038 (False Positive - memory leak (struct member passed to subfunction))

This commit is contained in:
Daniel Marjamäki 2011-08-26 19:26:21 +02:00
parent 19b7468bb6
commit 15e965b530
2 changed files with 14 additions and 2 deletions

View File

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

View File

@ -4994,6 +4994,7 @@ private:
TEST_CASE(function1); // Deallocating in function
TEST_CASE(function2); // #2848: Taking address in function
TEST_CASE(function3); // #3024: kernel list
TEST_CASE(function4); // #3038: Deallocating in function
// Handle if-else
TEST_CASE(ifelse);
@ -5199,6 +5200,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
// #3038: deallocating in function
void function4()
{
check("void a(char *p) { char *x = p; free(x); }\n"
"void b() {\n"
" struct ABC abc;\n"
" abc.a = (char *) malloc(10);\n"
" a(abc.a);\n"
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
}
void ifelse()
{
check("static void foo()\n"