Fixed #511 (false positive, memory leak when using 'var = ({});')

This commit is contained in:
Daniel Marjamäki 2009-07-31 23:42:21 +02:00
parent f11d34c109
commit b7ffcf53ba
2 changed files with 31 additions and 0 deletions

View File

@ -1647,6 +1647,15 @@ void CheckMemoryLeakInFunction::check()
else if (tok->str() == "}")
--indentlevel;
// Skip these weird blocks... "( { ... } )"
else if (Token::simpleMatch(tok, "( {"))
{
tok = tok->link();
if (!tok)
break;
continue;
}
// In function..
if (indentlevel == 0)
{

View File

@ -287,6 +287,9 @@ private:
TEST_CASE(pointer_to_pointer);
TEST_CASE(dealloc_and_alloc_in_func);
// Unknown syntax
TEST_CASE(unknownSyntax1);
}
@ -2452,6 +2455,25 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
void unknownSyntax1()
{
// I don't know what this syntax means so cppcheck should bail out
check("void foo()\n"
"{\n"
" void *sym = ( {\n"
" void *__ptr = malloc(100);\n"
" if(!__ptr && 100 != 0)\n"
" {\n"
" exit(1);\n"
" }\n"
" __ptr;\n"
" } );\n"
" free(sym);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
static TestMemleakInFunction testMemleakInFunction;