Fixed #3809 (false positive: memory leak)
This commit is contained in:
parent
63cc25d047
commit
a823d29da3
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue