Fix #7923 FN memleak with cfg (#4060)

This commit is contained in:
chrchr-github 2022-04-28 19:50:16 +02:00 committed by GitHub
parent 8dbe6994a2
commit 0467ab1339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -632,7 +632,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
// Handle scopes that might be noreturn
if (allocation.status == VarInfo::NOALLOC && Token::simpleMatch(tok, ") ; }")) {
const std::string &functionName(tok->link()->previous()->str());
const std::string functionName(mSettings->library.getFunctionName(tok->link()->previous()));
bool unknown = false;
if (mTokenizer->isScopeNoReturn(tok->tokAt(2), &unknown)) {
if (!unknown)
@ -847,7 +847,7 @@ void CheckLeakAutoVar::changeAllocStatus(VarInfo *varInfo, const VarInfo::AllocI
void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpeningPar, VarInfo *varInfo, const VarInfo::AllocInfo& allocation, const Library::AllocFunc* af)
{
// Ignore function call?
if (mSettings->library.isLeakIgnore(tokName->str()))
if (mSettings->library.isLeakIgnore(mSettings->library.getFunctionName(tokName)))
return;
if (mSettings->library.getReallocFuncInfo(tokName))
return;

View File

@ -214,6 +214,7 @@ private:
TEST_CASE(smartPtrInContainer); // #8262
TEST_CASE(functionCallCastConfig); // #9652
TEST_CASE(functionCallLeakIgnoreConfig); // #7923
}
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
@ -2360,6 +2361,27 @@ private:
"}", settingsFunctionCall);
ASSERT_EQUALS("[test.cpp:5]: (information) --check-library: Function free_func() should have <use>/<leak-ignore> configuration\n", errout.str());
}
void functionCallLeakIgnoreConfig() { // #7923
Settings settingsLeakIgnore = settings;
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <function name=\"SomeClass::someMethod\">\n"
" <leak-ignore/>\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\" direction=\"in\"/>\n"
" </function>\n"
"</def>\n";
tinyxml2::XMLDocument doc;
doc.Parse(xmldata, sizeof(xmldata));
settingsLeakIgnore.library.load(doc);
check("void f() {\n"
" double* a = new double[1024];\n"
" SomeClass::someMethod(a);\n"
"}\n", settingsLeakIgnore);
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str());
}
};
REGISTER_TEST(TestLeakAutoVar)