Fixed #2374 (False 'memory leak' report (assigning to map in subfunction))

This commit is contained in:
Daniel Marjamäki 2010-12-29 22:18:23 +01:00
parent 3900ac731e
commit 3d3593e6e7
2 changed files with 24 additions and 3 deletions

View File

@ -443,14 +443,16 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok)
{
allocType = getReallocationType(tok->tokAt(2), varid);
}
if (allocType != No)
return allocType;
}
if (Token::Match(tok, "= %varid% ;", varid))
{
return No;
}
if (tok->str() == "return")
return allocType;
}
return No;
return allocType;
}

View File

@ -234,6 +234,7 @@ private:
TEST_CASE(allocfunc4);
TEST_CASE(allocfunc5);
TEST_CASE(allocfunc6);
TEST_CASE(allocfunc7);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -1924,6 +1925,24 @@ private:
}
void allocfunc7()
{
// Ticket #2374 - no false positive
check("char *data()\n"
"{\n"
" char *s = malloc(100);\n"
" strings[0] = s;\n"
" return s;\n"
"}\n"
"\n"
"static void foo()\n"
"{\n"
" char* s = data();\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
void throw1()
{