Skip to content

Commit bfa26b5

Browse files
authored
Fix FP leakNoVarFunctionCall with passthrough returns (danmar#3249)
1 parent be95e2b commit bfa26b5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
996996
const Token* tok2 = tok->next()->astParent();
997997
while (tok2 && tok2->isCast())
998998
tok2 = tok2->astParent();
999-
if (tok2 && tok2->isAssignmentOp())
999+
if (Token::Match(tok2, "%assign%|return"))
10001000
continue;
10011001

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

test/testmemleak.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,11 @@ class TestMemleakNoVar : public TestFixture {
21732173
" return ret;\n"
21742174
"}");
21752175
ASSERT_EQUALS("", errout.str());
2176+
2177+
check("char *x() {\n"
2178+
" return strcpy(malloc(10), \"abc\");\n"
2179+
"}");
2180+
ASSERT_EQUALS("", errout.str());
21762181

21772182
check("void x() {\n"
21782183
" free(malloc(10));\n"

0 commit comments

Comments
 (0)