From ce0131a1e6276ff6239eaee28ff65e7ddb6d4e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 26 Feb 2010 22:14:56 +0100 Subject: [PATCH] Fixed #1397 (false positive: Memory leak in while loop) --- lib/tokenize.cpp | 2 ++ test/testsimplifytokens.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bf576d943..6214518ac 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2978,6 +2978,8 @@ bool Tokenizer::simplifyTokenList() simplifyNestedStrcat(); simplifyWhile0(); + simplifyIfAssign(); // could be affected by simplifyIfNot + for (Token *tok = _tokens; tok; tok = tok->next()) { if (Token::Match(tok, "case %any% : %var%")) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9961eecd9..7a73b593b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1700,6 +1700,8 @@ private: tok("struct hfs_bnode *node;" "struct hfs_btree *tree;" "while ((node = tree->node_hash[i++])) { }")); + ASSERT_EQUALS("char * s ; s = new char [ 10 ] ; while ( ! s ) { s = new char [ 10 ] ; }", + tok("char *s; while (0 == (s=new char[10])) { }")); }