Skip to content

Commit 0682db4

Browse files
author
Daniel Marjamäki
committed
Memory leaks: Detect simple leak
1 parent fad29ca commit 0682db4

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens, bool all)
17161716
return result;
17171717
}
17181718

1719-
if ((result = Token::findmatch(tokens, "alloc ; if return ;")) != NULL)
1719+
if ((result = Token::findmatch(tokens, "alloc ; if|if(var)|ifv return ;")) != NULL)
17201720
{
17211721
return result->tokAt(3);
17221722
}

test/testmemleak.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,12 @@ class TestMemleakInFunction : public TestFixture
532532
// replace "if ( ! var )" => "if(!var)"
533533
for (Token *tok = tokenizer._tokens; tok; tok = tok->next())
534534
{
535-
if (Token::simpleMatch(tok, "if ( var )"))
535+
if (tok->str() == "if_var")
536+
{
537+
tok->str("if(var)");
538+
}
539+
540+
else if (Token::simpleMatch(tok, "if ( var )"))
536541
{
537542
Token::eraseTokens(tok, tok->tokAt(4));
538543
tok->str("if(var)");
@@ -566,8 +571,9 @@ class TestMemleakInFunction : public TestFixture
566571
ASSERT_EQUALS(-1, dofindleak("if alloc;\n use;"));
567572

568573
// if..
569-
ASSERT_EQUALS(-1, dofindleak("alloc; ifv { dealloc; }"));
574+
ASSERT_EQUALS(-1, dofindleak("alloc; ifv dealloc;"));
570575
ASSERT_EQUALS(2, dofindleak("alloc;\n if return;\n dealloc;"));
576+
ASSERT_EQUALS(2, dofindleak("alloc;\n if_var return;\n dealloc;"));
571577
ASSERT_EQUALS(3, dofindleak("alloc;\n if\n return;\n dealloc;"));
572578
ASSERT_EQUALS(-1, dofindleak("alloc; if { dealloc ; return; } dealloc;"));
573579
ASSERT_EQUALS(-1, dofindleak("alloc; if { dealloc ; return; } dealloc;"));

0 commit comments

Comments
 (0)