From 04faae2882e932ab4ba6226bbbe0801adb7a41ee Mon Sep 17 00:00:00 2001 From: Leandro Penz Date: Sat, 24 Jan 2009 18:55:56 +0000 Subject: [PATCH] memleak: *x=malloc(); func(&x) is no longer reported as a leak (eliminated &use2). --- src/checkmemoryleak.cpp | 10 +++------- test/testmemleak.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 8970aaac1..6ddb7e0c5 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -652,14 +652,10 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list } // Linux lists.. - if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [.[]").c_str())) + if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [.[,)]").c_str())) { addtoken("&use"); } - else if (Token::Match(tok, std::string("[=(,] & " + varnameStr + " [,)]").c_str())) - { - addtoken("&use2"); - } } return rethead; @@ -1155,12 +1151,12 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c _errorLogger->reportErr(errmsg.str()); } - // Replace "&use" with "use". Replace "&use2" with ";" + // Replace "&use" with "use". Replace "use_" with ";" for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { if (tok2->str() == "&use") tok2->str("use"); - else if (tok2->str() == "&use2" || tok2->str() == "use_") + else if (tok2->str() == "use_") tok2->str(";"); else if (tok2->str() == "recursive") tok2->str("use"); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 48b185950..235e73d1b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -132,6 +132,7 @@ private: TEST_CASE(func10); // Bug 2458510 - Function pointer TEST_CASE(func11); // Bug 2458510 - Function pointer TEST_CASE(func12); + TEST_CASE(func13); TEST_CASE(class1); TEST_CASE(class2); @@ -1131,6 +1132,18 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void func13() + { + check("static void f()\n" + "{\n" + " char *p = malloc(100);\n" + " foo(&p);\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + + + /* void func3()