Fixed #789 (false positive: resource leak reported when using for loop)

This commit is contained in:
Daniel Marjamäki 2009-10-04 19:58:41 +02:00
parent 4a66edd408
commit 23d8937661
2 changed files with 3 additions and 1 deletions

View File

@ -916,7 +916,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// Loops.. // Loops..
else if ((tok->str() == "for") || (tok->str() == "while")) else if ((tok->str() == "for") || (tok->str() == "while"))
{ {
if (Token::simpleMatch(tok, "while ( true )")) if (Token::simpleMatch(tok, "while ( true )") ||
Token::simpleMatch(tok, "for ( ; ; )"))
{ {
addtoken("while1"); addtoken("while1");
tok = tok->next()->link(); tok = tok->next()->link();

View File

@ -361,6 +361,7 @@ private:
ASSERT_EQUALS(";;loop{alloc;}", getcode("char *s; for (a;b;c) { s=malloc(10); }", "s")); ASSERT_EQUALS(";;loop{alloc;}", getcode("char *s; for (a;b;c) { s=malloc(10); }", "s"));
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s")); ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
ASSERT_EQUALS(";;while1{}", getcode("char *s; while(true) { }", "s")); ASSERT_EQUALS(";;while1{}", getcode("char *s; while(true) { }", "s"));
ASSERT_EQUALS(";;while1{}", getcode("char *s; for(;;) { }", "s"));
// asprintf.. // asprintf..
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s")); ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));