Skip to content

Commit 54b6b8e

Browse files
committed
Fixed false positive cppcheck-opensource#6481
1 parent 21cb0cf commit 54b6b8e

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
@@ -2745,7 +2745,7 @@ void CheckMemoryLeakNoVar::check()
27452745
void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
27462746
{
27472747
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
2748-
if (Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp())) {
2748+
if (Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) {
27492749
const AllocType allocType = getAllocationType(tok, 0);
27502750
if (allocType != No)
27512751
returnValueNotUsedError(tok, tok->str());

test/testmemleak.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6503,6 +6503,12 @@ class TestMemleakNoVar : public TestFixture {
65036503
" if(!malloc(5)) fail();\n"
65046504
"}");
65056505
ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function malloc is not stored.\n", errout.str());
6506+
6507+
check("FOO* factory() {\n"
6508+
" FOO* foo = new (std::nothrow) FOO;\n"
6509+
" return foo;\n"
6510+
"}");
6511+
ASSERT_EQUALS("", errout.str());
65066512
}
65076513

65086514
void smartPointerFunctionParam() {

0 commit comments

Comments
 (0)