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.