Skip to content

Commit 2945030

Browse files
Fix #14706 FP Memleak struct member when struct is passed to function (#8509)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 1f41e56 commit 2945030

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable* const vari
787787
bool deallocated = false;
788788
const Token* const end = tok->linkAt(1);
789789
for (const Token* tok2 = tok; tok2 != end; tok2 = tok2->next()) {
790-
if (Token::Match(tok2, "[(,] &| %varid% [,)]", structid)) {
790+
if (Token::Match(tok2, "%varid%", structid)) {
791791
/** @todo check if the function deallocates the memory */
792792
deallocated = true;
793793
break;

test/testmemleak.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ class TestMemleakStructMember : public TestFixture {
16841684
TEST_CASE(function3); // #3024: kernel list
16851685
TEST_CASE(function4); // #3038: Deallocating in function
16861686
TEST_CASE(function5); // #10381, #10382, #10158
1687+
TEST_CASE(function6);
16871688

16881689
// Handle if-else
16891690
TEST_CASE(ifelse);
@@ -2082,6 +2083,17 @@ class TestMemleakStructMember : public TestFixture {
20822083
ASSERT_EQUALS("", errout_str());
20832084
}
20842085

2086+
void function6() {
2087+
check("struct S { int* p; };\n" // #14706
2088+
"void g(void*);\n"
2089+
"void f() {\n"
2090+
" S* s = new S();\n"
2091+
" s->p = new int();\n"
2092+
" g((void*)s);\n"
2093+
"}");
2094+
ASSERT_EQUALS("", errout_str());
2095+
}
2096+
20852097
void ifelse() {
20862098
check("static void foo()\n"
20872099
"{\n"

0 commit comments

Comments
 (0)