Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 72d24ab4b46f0534e53c2fa7eb4c70344d06c8ba 1 parent 162a430
Daniel Marjamäki authored June 23, 2012
2  lib/checkmemoryleak.cpp
@@ -2641,6 +2641,8 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var
2641 2641
                 // struct assignment..
2642 2642
                 else if (Token::Match(tok3, "= %varid% ;", structid)) {
2643 2643
                     break;
  2644
+                } else if (Token::Match(tok3, "= %var% . %varid% ;", structmemberid)) {
  2645
+                    break;
2644 2646
                 }
2645 2647
 
2646 2648
                 // goto isn't handled well.. bail out even though there might be leaks
18  test/testmemleak.cpp
@@ -4960,6 +4960,9 @@ class TestMemleakStructMember : public TestFixture {
4960 4960
         // Handle if-else
4961 4961
         TEST_CASE(ifelse);
4962 4962
 
  4963
+        // Linked list
  4964
+        TEST_CASE(linkedlist);
  4965
+
4963 4966
         // struct variable is a global variable
4964 4967
         TEST_CASE(globalvar);
4965 4968
 
@@ -5180,6 +5183,21 @@ class TestMemleakStructMember : public TestFixture {
5180 5183
         ASSERT_EQUALS("", errout.str());
5181 5184
     }
5182 5185
 
  5186
+    void linkedlist() {
  5187
+        check("static void foo() {\n"
  5188
+              "    struct ABC *abc = malloc(sizeof(struct ABC));\n"
  5189
+              "    abc->next = malloc(sizeof(struct ABC));\n"
  5190
+              "    abc->next->next = NULL;\n"
  5191
+              "\n"
  5192
+              "    while (abc) {\n"
  5193
+              "        struct ABC *next = abc->next;\n"
  5194
+              "        free(abc);\n"
  5195
+              "        abc = next;\n"
  5196
+              "    }\n"
  5197
+              "}");
  5198
+        ASSERT_EQUALS("", errout.str());
  5199
+    }
  5200
+
5183 5201
     void globalvar() {
5184 5202
         check("struct ABC *abc;\n"
5185 5203
               "\n"

0 notes on commit 72d24ab

Please sign in to comment.
Something went wrong with that request. Please try again.