Fix FP leakNoVarFunctionCall (#4241)

* Fix #10857 FN: leakNoVarFunctionCall

* Fix TODO

* Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) )

* #11155 FN: leakNoVarFunctionCall (ternary operator)

* Fix #11157 FN: leakNoVarFunctionCall (switch condition)

* Fix FN constStatement

* Fix FP leakNoVarFunctionCall

* Fix FP leakNoVarFunctionCall

* Format
This commit is contained in:
chrchr-github 2022-06-29 07:22:26 +02:00 committed by GitHub
parent 185294499c
commit b90a726441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -998,7 +998,9 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
const Token* tok2 = tok->next()->astParent();
while (tok2 && tok2->isCast())
tok2 = tok2->astParent();
if (Token::Match(tok2, "%assign%|return"))
if (Token::Match(tok2, "%assign%"))
continue;
if (Token::simpleMatch(tok->astTop(), "return"))
continue;
const std::string& functionName = tok->str();

View File

@ -2407,6 +2407,14 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (error) Allocation with new, if doesn't release it.\n"
"[test.cpp:2]: (error) Allocation with malloc, if doesn't release it.\n",
errout.str());
check("const char* string(const char* s) {\n"
" StringSet::iterator it = strings_.find(s);\n"
" if (it != strings_.end())\n"
" return *it;\n"
" return *strings_.insert(it, std::strcpy(new char[std::strlen(s) + 1], s));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void missingAssignment() {