Skip to content

Commit e7e23e8

Browse files
Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) (#4237)
* Fix #10857 FN: leakNoVarFunctionCall * Fix TODO * Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) )
1 parent 88bf11a commit e7e23e8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
10701070
if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link())))
10711071
continue;
10721072
returnValueNotUsedError(tok, tok->str());
1073-
} else if (Token::Match(parent, "%comp%|!|,")) {
1073+
} else if (Token::Match(parent, "%comp%|!|,|%oror%|&&")) {
10741074
if (!(parent->astParent() && parent->str() == ","))
10751075
returnValueNotUsedError(tok, tok->str());
10761076
}

test/testmemleak.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,12 @@ class TestMemleakNoVar : public TestFixture {
26012601
" C{ new QWidget, 1 };\n"
26022602
"}");
26032603
ASSERT_EQUALS("", errout.str());
2604+
2605+
check("void f(bool b) { if (b && malloc(42)) {} }\n" // // #10858
2606+
"void g(bool b) { if (b || malloc(42)) {} }\n");
2607+
ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'malloc' is not stored.\n"
2608+
"[test.cpp:2]: (error) Return value of allocation function 'malloc' is not stored.\n",
2609+
errout.str());
26042610
}
26052611

26062612
void smartPointerFunctionParam() {

0 commit comments

Comments
 (0)