From 1427f0a2c75d6bc7969253cff18bcc16fd7066c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 28 Sep 2009 22:41:45 +0200 Subject: [PATCH] memory leaks: fixed a TODO_ASSERT_EQUALS for a false positive --- src/checkmemoryleak.cpp | 29 +++++++++++++++++++++++++++++ test/testmemleak.cpp | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index a5fcf58fd..1b7e7a40d 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -2243,6 +2243,35 @@ void CheckMemoryLeakStructMember::check() tok3 = tok3->next()->link(); } + // succeeded allocation + else if (Token::Match(tok3, "if ( %var% . %varid% ) {", structmemberid)) + { + // goto the ")" + tok3 = tok3->next()->link(); + + // check if the variable is deallocated or returned.. + unsigned int indentlevel4 = 0; + for (const Token *tok4 = tok3; tok4; tok4 = tok4->next()) + { + if (tok4->str() == "{") + ++indentlevel4; + else if (tok4->str() == "}") + { + --indentlevel4; + if (indentlevel4 == 0) + break; + } + else if (Token::Match(tok4, "free|kfree ( %var% . %varid% )", structmemberid)) + { + break; + } + } + + // was there a proper deallocation? + if (indentlevel4 > 0) + break; + } + // Returning from function.. else if (tok3->str() == "return") { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 11454edf1..d0bf69c48 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2792,7 +2792,7 @@ private: " free(abc->a);\n" " free(abc);\n" "}\n"); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); } void ret()