From 23d8937661b1459917d55cb06f09a919c5b39455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Oct 2009 19:58:41 +0200 Subject: [PATCH] Fixed #789 (false positive: resource leak reported when using for loop) --- src/checkmemoryleak.cpp | 3 ++- test/testmemleak.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index b621d7427..7fc53f483 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -916,7 +916,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == "for") || (tok->str() == "while")) { - if (Token::simpleMatch(tok, "while ( true )")) + if (Token::simpleMatch(tok, "while ( true )") || + Token::simpleMatch(tok, "for ( ; ; )")) { addtoken("while1"); tok = tok->next()->link(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c4390bfea..38db4edea 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -361,6 +361,7 @@ private: 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(";;while1{}", getcode("char *s; while(true) { }", "s")); + ASSERT_EQUALS(";;while1{}", getcode("char *s; for(;;) { }", "s")); // asprintf.. ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));