From 8e3f1702fdcc25832f156047fbfd2a28be62b251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 10 Apr 2012 13:58:59 +0200 Subject: [PATCH] Reverted 81318b3f to get rid of #3669 false positives --- lib/checkmemoryleak.cpp | 15 --------------- lib/checkmemoryleak.h | 3 --- test/testmemleak.cpp | 4 ++-- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 11b98cd23..07fe96517 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2877,11 +2877,6 @@ void CheckMemoryLeakNoVar::check() } } } - - // Handle the case where the user is calling an allocation function - // and never assigns the returned value to a variable, which will lead to a leak. - else if (Token::Match(tok2, "[;{}] %var% (") && getAllocationType(tok2->next(), 0) != No) - missingAssignementLeak(tok2->next(), tok2->next()->str()); } } } @@ -2891,13 +2886,3 @@ void CheckMemoryLeakNoVar::functionCallLeak(const Token *loc, const std::string reportError(loc, Severity::error, "leakNoVarFunctionCall", "Allocation with " + alloc + ", " + functionCall + " doesn't release it."); } -void CheckMemoryLeakNoVar::missingAssignementLeak(const Token *loc, const std::string &alloc) -{ - reportError(loc, Severity::error, "leakNoVar", - "Return value of allocation function " + alloc + " is not used.\n" - "Return value of allocation function " + alloc + " is not used and this can lead to a memory leak. " - "When the allocation succeeds the function returns a pointer to the allocated memory which " - "needs to be freed."); -} - - diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 9c263f5ee..f2063c1e3 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -459,13 +459,10 @@ private: void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall); - void missingAssignementLeak(const Token *loc, const std::string &alloc); - void getErrorMessages(ErrorLogger *e, const Settings *settings) const { CheckMemoryLeakNoVar c(0, settings, e); c.functionCallLeak(0, "funcName", "funcName"); - c.missingAssignementLeak(0, "funcName"); } std::string myName() const { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 8a9700c6b..2d15c5db7 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5250,7 +5250,7 @@ private: "{\n" " malloc(10);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function malloc is not used.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function malloc is not used.\n", "", errout.str()); check("void *f()\n" "{\n" @@ -5260,7 +5260,7 @@ private: "{\n" " f();\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Return value of allocation function f is not used.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Return value of allocation function f is not used.\n", "", errout.str()); } }; static TestMemleakNoVar testMemleakNoVar;