From 3d0e090a13c467c285567631dec747b5ea04d9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 20 Jun 2012 17:09:41 +0200 Subject: [PATCH] Fixed #3899 (false positive: (error) Returning/using deallocated pointer fp) --- lib/checkleakautovar.cpp | 4 +++- test/testleakautovar.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index acb29749b..2f1f0f271 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -147,7 +147,9 @@ void CheckLeakAutoVar::check() std::map::iterator it = varInfo.alloctype.begin(); while (it != varInfo.alloctype.end()) { const Variable *var = symbolDatabase->getVariableFromVarId(it->first); - if (var && var->isArgument() && var->isReference()) + if (!var || + (var->isArgument() && var->isReference()) || + (!var->isArgument() && !var->isLocal())) varInfo.alloctype.erase(it++); else ++it; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index bfebd5d0f..2de124b49 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -81,6 +81,7 @@ private: // General tests: variable type, allocation type, etc TEST_CASE(test1); + TEST_CASE(test2); // Possible leak => Further configuration is needed for complete analysis TEST_CASE(configuration1); @@ -438,6 +439,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void test2() { // 3899 + check("struct Fred {\n" + " char *p;\n" + " void f1() { free(p); }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void configuration1() { // Possible leak => configuration is required for complete analysis // The user should be able to "white list" and "black list" functions.