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:
Reijo Tomperi 2009-05-19 23:29:10 +03:00
parent a3f469d339
commit 9c60391375
2 changed files with 14 additions and 0 deletions

View File

@ -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",

View File

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