Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable* const vari
bool deallocated = false;
const Token* const end = tok->linkAt(1);
for (const Token* tok2 = tok; tok2 != end; tok2 = tok2->next()) {
if (Token::Match(tok2, "[(,] &| %varid% [,)]", structid)) {
if (Token::Match(tok2, "%varid%", structid)) {
/** @todo check if the function deallocates the memory */
deallocated = true;
break;
Expand Down
12 changes: 12 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ class TestMemleakStructMember : public TestFixture {
TEST_CASE(function3); // #3024: kernel list
TEST_CASE(function4); // #3038: Deallocating in function
TEST_CASE(function5); // #10381, #10382, #10158
TEST_CASE(function6);

// Handle if-else
TEST_CASE(ifelse);
Expand Down Expand Up @@ -2082,6 +2083,17 @@ class TestMemleakStructMember : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void function6() {
check("struct S { int* p; };\n" // #14706
"void g(void*);\n"
"void f() {\n"
" S* s = new S();\n"
" s->p = new int();\n"
" g((void*)s);\n"
"}");
ASSERT_EQUALS("", errout_str());
}

void ifelse() {
check("static void foo()\n"
"{\n"
Expand Down
Loading