Skip to content

Commit b90a726

Browse files
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
1 parent 1852944 commit b90a726

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkmemoryleak.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
998998
const Token* tok2 = tok->next()->astParent();
999999
while (tok2 && tok2->isCast())
10001000
tok2 = tok2->astParent();
1001-
if (Token::Match(tok2, "%assign%|return"))
1001+
if (Token::Match(tok2, "%assign%"))
1002+
continue;
1003+
if (Token::simpleMatch(tok->astTop(), "return"))
10021004
continue;
10031005

10041006
const std::string& functionName = tok->str();

test/testmemleak.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,14 @@ class TestMemleakNoVar : public TestFixture {
24072407
ASSERT_EQUALS("[test.cpp:1]: (error) Allocation with new, if doesn't release it.\n"
24082408
"[test.cpp:2]: (error) Allocation with malloc, if doesn't release it.\n",
24092409
errout.str());
2410+
2411+
check("const char* string(const char* s) {\n"
2412+
" StringSet::iterator it = strings_.find(s);\n"
2413+
" if (it != strings_.end())\n"
2414+
" return *it;\n"
2415+
" return *strings_.insert(it, std::strcpy(new char[std::strlen(s) + 1], s));\n"
2416+
"}\n");
2417+
ASSERT_EQUALS("", errout.str());
24102418
}
24112419

24122420
void missingAssignment() {

0 commit comments

Comments
 (0)