Apply patch #320 from php-coderrr ([PATCH] Determine memory leaks after strndup() usage)
http://apps.sourceforge.net/trac/cppcheck/ticket/320
This commit is contained in:
parent
a3f469d339
commit
9c60391375
|
@ -57,6 +57,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType(const To
|
|||
// * var = (char *)malloc(10);
|
||||
// * var = new char[10];
|
||||
// * var = strdup("hello");
|
||||
// * var = strndup("hello", 3);
|
||||
if (tok2 && tok2->str() == "(")
|
||||
{
|
||||
while (tok2 && tok2->str() != ")")
|
||||
|
@ -72,6 +73,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType(const To
|
|||
const char *mallocfunc[] = {"malloc",
|
||||
"calloc",
|
||||
"strdup",
|
||||
"strndup",
|
||||
"kmalloc",
|
||||
"kzalloc",
|
||||
"kcalloc",
|
||||
|
|
|
@ -213,6 +213,8 @@ private:
|
|||
TEST_CASE(exit1);
|
||||
TEST_CASE(exit2);
|
||||
TEST_CASE(stdstring);
|
||||
|
||||
TEST_CASE(strndup_function);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2165,6 +2167,16 @@ private:
|
|||
|
||||
TODO_ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: out\n"), err);
|
||||
}
|
||||
|
||||
void strndup_function()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" char *out = strndup(\"text\", 3);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: out\n"), errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestMemleak)
|
||||
|
|
Loading…
Reference in New Issue