Fixed #1346 (False positive: Memory leak when allocated memory is stored elsewhere inside a condition)

This commit is contained in:
Daniel Marjamäki 2010-02-06 22:35:36 +01:00
parent 71117378ef
commit e1b54df368
2 changed files with 28 additions and 1 deletions

View File

@ -639,7 +639,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
while (ftok && (ftok->str() != "{"))
ftok = ftok->next();
Token *func = getcode(ftok->tokAt(1), callstack, parameterVarid, alloctype, dealloctype, false, all, sz);
simplifycode(func, all);
//simplifycode(func, all);
const Token *func_ = func;
while (func_ && func_->str() == ";")
func_ = func_->next();

View File

@ -295,6 +295,7 @@ private:
TEST_CASE(func14);
TEST_CASE(func15);
TEST_CASE(func16);
TEST_CASE(func17);
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
@ -1580,6 +1581,32 @@ private:
}
void func17()
{
// The "bar" function must be reduced to "use"
check("bool bar(char **parent, char *res, bool a)\n"
"{\n"
" if( a )\n"
" {\n"
" *parent = res;\n"
" return false;\n"
" }\n"
" return true;\n"
"}\n"
"\n"
"void foo(char **parent, bool a)\n"
"{\n"
" if (a)\n"
" {\n"
" char *res = malloc(65);\n"
" bar(parent, res, a);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1()
{