Fixed #3038 (False Positive - memory leak (struct member passed to subfunction))
This commit is contained in:
parent
19b7468bb6
commit
15e965b530
|
@ -3209,8 +3209,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Token * const vartok
|
||||||
break;
|
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 */
|
/** @todo check if the function deallocates the memory */
|
||||||
deallocated = true;
|
deallocated = true;
|
||||||
|
|
|
@ -4994,6 +4994,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
|
TEST_CASE(function3); // #3024: kernel list
|
||||||
|
TEST_CASE(function4); // #3038: Deallocating in function
|
||||||
|
|
||||||
// Handle if-else
|
// Handle if-else
|
||||||
TEST_CASE(ifelse);
|
TEST_CASE(ifelse);
|
||||||
|
@ -5199,6 +5200,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void ifelse()
|
||||||
{
|
{
|
||||||
check("static void foo()\n"
|
check("static void foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue