Fixed #3809 (false positive: memory leak)

This commit is contained in:
Daniel Marjamäki 2012-06-01 19:01:19 +02:00
parent 63cc25d047
commit a823d29da3
4 changed files with 26 additions and 9 deletions

View File

@ -143,6 +143,16 @@ void CheckLeakAutoVar::check()
varInfo.conditionalAlloc.clear();
// Clear reference arguments from varInfo..
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())
varInfo.alloctype.erase(it++);
else
++it;
}
ret(i->classEnd, varInfo);
}
}

View File

@ -2228,6 +2228,9 @@ void CheckMemoryLeakInFunction::check()
if (!var || (!var->isLocal() && !var->isArgument()) || var->isStatic() || !var->scope())
continue;
if (var->isArgument() && var->isReference())
continue;
if (!var->isPointer() && var->typeStartToken()->str() != "int")
continue;

View File

@ -78,6 +78,9 @@ private:
TEST_CASE(return2);
TEST_CASE(return3);
// General tests: variable type, allocation type, etc
TEST_CASE(test1);
// Possible leak => Further configuration is needed for complete analysis
TEST_CASE(configuration1);
TEST_CASE(configuration2);
@ -378,6 +381,13 @@ private:
ASSERT_EQUALS("", errout.str());
}
void test1() { // 3809
check("void f(double*&p) {\n"
" p = malloc(0x100);\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.

View File

@ -2515,16 +2515,10 @@ private:
}
void allocfunc11() { // ticket #3809 - false positive
check("class A \n"
"{\n"
" public:\n"
" virtual void f (double * & data_val) ;\n"
"};\n"
"void A::f (double * & data_val) \n"
"{\n"
" data_val = new double [10];\n"
check("void f (double * & data_val) {\n"
" data_val = malloc(0x100);\n"
"}\n");
TODO_ASSERT_EQUALS("","[test.cpp:9]: (error) Memory leak: data_val\n", errout.str());
ASSERT_EQUALS("", errout.str());
}
void throw1() {