Fixed #1407 (false positive memory leak when returning pointer to the allocated memory)

This commit is contained in:
Daniel Marjamäki 2010-02-20 10:17:45 +01:00
parent d0348fa57a
commit a6c9a6fc54
2 changed files with 5 additions and 2 deletions

View File

@ -1586,9 +1586,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
}
// Reduce "alloc|dealloc|use|callfunc ; exit ;" => "; exit ;"
if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;"))
if (Token::Match(tok2, "[;{}] alloc|dealloc|use|callfunc ; exit ;"))
{
tok2->deleteThis();
tok2->deleteNext();
done = false;
}

View File

@ -665,6 +665,9 @@ private:
ASSERT_EQUALS("; alloc ; return ;", simplifycode(";alloc;if{return;}return;"));
ASSERT_EQUALS("; alloc ; assign ; dealloc ;", simplifycode(";alloc;if{assign;}dealloc;"));
// if(var)
ASSERT_EQUALS("; alloc ; return use ;", simplifycode("; alloc ; return use ;"));
// switch..
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;"));
ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; return ; default ; break ; }"));