From 7e0fc3d48149661fb51096103b3d5fd77337e5ef Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Mon, 3 Nov 2014 21:24:34 +0100 Subject: [PATCH] Fixed #6252 (False positive "freed twice") --HG-- extra : rebase_source : 24f801452fbefa3a59ab2cca62c3cf02aea513b6 --- lib/checkother.cpp | 2 ++ test/testother.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e2fa8eabb..802eb3059 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2112,6 +2112,8 @@ void CheckOther::checkDoubleFree() const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase(); const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { + freedVariables.clear(); + closeDirVariables.clear(); const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { // Keep track of any variables passed to "free()", "g_free()" or "closedir()", diff --git a/test/testother.cpp b/test/testother.cpp index c18c9145e..08b0d4cc3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5146,7 +5146,21 @@ private: ); ASSERT_EQUALS("", errout.str()); - + check( // #6252 + "struct Wrapper {\n" + " Thing* m_thing;\n" + " Wrapper() : m_thing(0) {\n" + " }\n" + " ~Wrapper() {\n" + " delete m_thing;\n" + " }\n" + " void changeThing() {\n" + " delete m_thing;\n" + " m_thing = new Thing;\n" + " }\n" + "};\n" + ); + ASSERT_EQUALS("", errout.str()); }