Fixed #6397 (FP deallocuse - conditional deallocation and conditional return)
This commit is contained in:
parent
9d1302d523
commit
2668cee3cf
|
@ -362,8 +362,20 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
VarInfo old;
|
VarInfo old;
|
||||||
old.swap(*varInfo);
|
old.swap(*varInfo);
|
||||||
|
|
||||||
// Conditional allocation in varInfo1
|
|
||||||
std::map<unsigned int, VarInfo::AllocInfo>::const_iterator it;
|
std::map<unsigned int, VarInfo::AllocInfo>::const_iterator it;
|
||||||
|
|
||||||
|
for (it = old.alloctype.begin(); it != old.alloctype.end(); ++it) {
|
||||||
|
const unsigned int varId = it->first;
|
||||||
|
if (old.conditionalAlloc.find(varId) == old.conditionalAlloc.end())
|
||||||
|
continue;
|
||||||
|
if (varInfo1.alloctype.find(varId) == varInfo1.alloctype.end() ||
|
||||||
|
varInfo2.alloctype.find(varId) == varInfo2.alloctype.end()) {
|
||||||
|
varInfo1.erase(varId);
|
||||||
|
varInfo2.erase(varId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conditional allocation in varInfo1
|
||||||
for (it = varInfo1.alloctype.begin(); it != varInfo1.alloctype.end(); ++it) {
|
for (it = varInfo1.alloctype.begin(); it != varInfo1.alloctype.end(); ++it) {
|
||||||
if (varInfo2.alloctype.find(it->first) == varInfo2.alloctype.end() &&
|
if (varInfo2.alloctype.find(it->first) == varInfo2.alloctype.end() &&
|
||||||
old.alloctype.find(it->first) == old.alloctype.end()) {
|
old.alloctype.find(it->first) == old.alloctype.end()) {
|
||||||
|
|
|
@ -98,6 +98,7 @@ private:
|
||||||
TEST_CASE(return2);
|
TEST_CASE(return2);
|
||||||
TEST_CASE(return3);
|
TEST_CASE(return3);
|
||||||
TEST_CASE(return4);
|
TEST_CASE(return4);
|
||||||
|
TEST_CASE(return5);
|
||||||
|
|
||||||
// General tests: variable type, allocation type, etc
|
// General tests: variable type, allocation type, etc
|
||||||
TEST_CASE(test1);
|
TEST_CASE(test1);
|
||||||
|
@ -1043,6 +1044,20 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void return5() { // ticket #6397 - conditional allocation/deallocation and conditional return
|
||||||
|
// avoid false positives
|
||||||
|
check("void f(int *p, int x) {\n"
|
||||||
|
" if (x != 0) {\n"
|
||||||
|
" free(p);\n"
|
||||||
|
" }\n"
|
||||||
|
" if (x != 0) {\n"
|
||||||
|
" return;\n"
|
||||||
|
" }\n"
|
||||||
|
" *p = 0;\n"
|
||||||
|
"}", true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void test1() { // 3809
|
void test1() { // 3809
|
||||||
check("void f(double*&p) {\n"
|
check("void f(double*&p) {\n"
|
||||||
" p = malloc(0x100);\n"
|
" p = malloc(0x100);\n"
|
||||||
|
|
Loading…
Reference in New Issue