Reverted 81318b3f to get rid of #3669 false positives

This commit is contained in:
Daniel Marjamäki 2012-04-10 13:58:59 +02:00
parent 23c71daf37
commit 8e3f1702fd
3 changed files with 2 additions and 20 deletions

View File

@ -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.");
}

View File

@ -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 {

View File

@ -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;