Fixed #1790 (mismatching allocation/deallocation false positive)
This commit is contained in:
parent
5ea28ccbba
commit
3205775eb9
|
@ -694,6 +694,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
}
|
||||
|
||||
// Check if this is a function that allocates memory..
|
||||
if (Token::Match(tok->tokAt(-3), "[;{}] %varid% = %var% (", varid))
|
||||
{
|
||||
const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
|
||||
AllocType a = functionReturnType(ftok);
|
||||
|
|
|
@ -298,6 +298,7 @@ private:
|
|||
TEST_CASE(allocfunc3);
|
||||
TEST_CASE(allocfunc4);
|
||||
TEST_CASE(allocfunc5);
|
||||
TEST_CASE(allocfunc6);
|
||||
|
||||
TEST_CASE(throw1);
|
||||
TEST_CASE(throw2);
|
||||
|
@ -1808,10 +1809,28 @@ private:
|
|||
" free(tmp);\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS(std::string(""), errout.str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
void allocfunc6()
|
||||
{
|
||||
check("static FILE* data()\n"
|
||||
"{\n"
|
||||
" return fopen(\"data.txt\",\"rt\");\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static void foo()\n"
|
||||
"{\n"
|
||||
" char* expr;\n"
|
||||
" func(&expr);\n"
|
||||
"\n"
|
||||
" FILE *f = data();\n"
|
||||
" fclose(f);\n"
|
||||
"\n"
|
||||
" free(expr);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue