Memory leaks: Fixed bug in CheckMemoryLeak::functionReturnType

This commit is contained in:
Daniel Marjamäki 2010-05-30 20:30:08 +02:00
parent 08b6e6ee09
commit 9b1ed1112b
2 changed files with 34 additions and 0 deletions

View File

@ -414,6 +414,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok)
{
if (indentlevel <= 1)
return No;
--indentlevel;
}
if (Token::Match(tok2, "return %var% ;"))
{
@ -542,7 +543,9 @@ static int countParameters(const Token *tok)
}
else if (parlevel == 1 && tok->str() == ",")
{
++numpar;
}
}
return -1;

View File

@ -292,6 +292,7 @@ private:
TEST_CASE(func15);
TEST_CASE(func16);
TEST_CASE(func17);
TEST_CASE(func18);
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
@ -1587,6 +1588,36 @@ private:
}
void func18()
{
// No false positive
// The "free_pointers" will deallocate all pointers
check("static void free_pointers(int arg_count, ...)\n"
"{\n"
" va_list a;\n"
" va_start(a, arg_count);\n"
" for (int i = 0; i < arg_count; i++)\n"
" {\n"
" free(va_arg(a, void *));\n"
" }\n"
" va_end(a);\n"
"}\n"
"\n"
"static char* foo()\n"
"{\n"
" return strdup("");\n"
"}\n"
"\n"
"static void bar()\n"
"{\n"
" int *p = malloc(16);\n"
" free_pointers(1, p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1()
{