From 9fe9944adb2a6916b662712408d01cbd1f8f7d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 28 Aug 2012 06:38:38 +0200 Subject: [PATCH] Fixed #4034 (false positive:(error) Dereferencing 'cfileP' after it is deallocated / released) --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 5a804189a..7967b5586 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -240,7 +240,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (tok->varId() > 0) { const std::map::iterator var = alloctype.find(tok->varId()); if (var != alloctype.end()) { - if (var->second == "dealloc" && !Token::Match(tok->previous(), "[;{},] %var% =")) { + if (var->second == "dealloc" && !Token::Match(tok->previous(), "[;{},=] %var% =")) { deallocUseError(tok, tok->str()); } else if (Token::simpleMatch(tok->tokAt(-2), "= &")) { varInfo->erase(tok->varId()); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index afeec8a3c..4a427787a 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -50,6 +50,7 @@ private: TEST_CASE(deallocuse3); TEST_CASE(deallocuse4); TEST_CASE(deallocuse5); // #4018: FP. free(p), p = 0; + TEST_CASE(deallocuse6); // #4034: FP. x = p = f(); TEST_CASE(doublefree1); TEST_CASE(doublefree2); @@ -264,6 +265,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void deallocuse6() { // #4034 + check("void f(char *p) {\n" + " free(p);\n" + " x = p = foo();\n" // <- p is not dereferenced + "}"); + ASSERT_EQUALS("", errout.str()); + } + void doublefree1() { // #3895 check("void f(char *p) {\n" " if (x)\n"