Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #3904 (false positive memory leak with linked list)

  • Loading branch information...
commit 72d24ab4b46f0534e53c2fa7eb4c70344d06c8ba 1 parent 162a430
@danmar authored
Showing with 20 additions and 0 deletions.
  1. +2 −0  lib/checkmemoryleak.cpp
  2. +18 −0 test/testmemleak.cpp
View
2  lib/checkmemoryleak.cpp
@@ -2641,6 +2641,8 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var
// struct assignment..
else if (Token::Match(tok3, "= %varid% ;", structid)) {
break;
+ } else if (Token::Match(tok3, "= %var% . %varid% ;", structmemberid)) {
+ break;
}
// goto isn't handled well.. bail out even though there might be leaks
View
18 test/testmemleak.cpp
@@ -4960,6 +4960,9 @@ class TestMemleakStructMember : public TestFixture {
// Handle if-else
TEST_CASE(ifelse);
+ // Linked list
+ TEST_CASE(linkedlist);
+
// struct variable is a global variable
TEST_CASE(globalvar);
@@ -5180,6 +5183,21 @@ class TestMemleakStructMember : public TestFixture {
ASSERT_EQUALS("", errout.str());
}
+ void linkedlist() {
+ check("static void foo() {\n"
+ " struct ABC *abc = malloc(sizeof(struct ABC));\n"
+ " abc->next = malloc(sizeof(struct ABC));\n"
+ " abc->next->next = NULL;\n"
+ "\n"
+ " while (abc) {\n"
+ " struct ABC *next = abc->next;\n"
+ " free(abc);\n"
+ " abc = next;\n"
+ " }\n"
+ "}");
+ ASSERT_EQUALS("", errout.str());
+ }
+
void globalvar() {
check("struct ABC *abc;\n"
"\n"
Please sign in to comment.
Something went wrong with that request. Please try again.