Memory leaks: Fixed false positive for 'char *p = strcpy(malloc(10),str);'
This commit is contained in:
parent
17842394c0
commit
688e290332
|
@ -2889,7 +2889,7 @@ void CheckMemoryLeakNoVar::check()
|
||||||
for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous()) {
|
for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous()) {
|
||||||
if (tok3->str() == "(") {
|
if (tok3->str() == "(") {
|
||||||
// Is it a function call..
|
// Is it a function call..
|
||||||
if (Token::Match(tok3->tokAt(-2), "[(,;{}=] %var% (")) {
|
if (Token::Match(tok3->tokAt(-2), "[;{}] %var% (")) {
|
||||||
const std::string functionName = tok3->strAt(-1);
|
const std::string functionName = tok3->strAt(-1);
|
||||||
if (functionName == "delete" ||
|
if (functionName == "delete" ||
|
||||||
functionName == "free" ||
|
functionName == "free" ||
|
||||||
|
|
|
@ -5167,6 +5167,12 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with strdup, strcpy doesn't release it.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with strdup, strcpy doesn't release it.\n", errout.str());
|
||||||
|
|
||||||
|
check("char *x() {\n"
|
||||||
|
" char *ret = strcpy(malloc(10), \"abc\");\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void x() {\n"
|
check("void x() {\n"
|
||||||
" free(malloc(10));\n"
|
" free(malloc(10));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
@ -5187,7 +5193,7 @@ private:
|
||||||
" fd = mkstemp(strdup(\"/tmp/file.XXXXXXXX\"));\n"
|
" fd = mkstemp(strdup(\"/tmp/file.XXXXXXXX\"));\n"
|
||||||
" close(fd);\n"
|
" close(fd);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static TestMemleakNoVar testMemleakNoVar;
|
static TestMemleakNoVar testMemleakNoVar;
|
||||||
|
|
Loading…
Reference in New Issue