Fixed #3899 (false positive: (error) Returning/using deallocated pointer fp)

This commit is contained in:
Daniel Marjamäki 2012-06-20 17:09:41 +02:00
parent 180bb00ac6
commit 3d0e090a13
2 changed files with 12 additions and 1 deletions

View File

@ -147,7 +147,9 @@ void CheckLeakAutoVar::check()
std::map<unsigned int, std::string>::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;

View File

@ -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.