memleak: removed false positives for mismatching allocation and deallocation
This commit is contained in:
parent
a06861948b
commit
7299d3e5b1
|
@ -419,13 +419,17 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
{
|
{
|
||||||
if (! realloc)
|
if (! realloc)
|
||||||
addtoken("alloc");
|
addtoken("alloc");
|
||||||
if ((alloctype != No && alloctype != alloc) ||
|
|
||||||
(dealloctype != No && dealloctype != alloc))
|
if (alloctype != No && alloctype != alloc)
|
||||||
|
alloc = Many;
|
||||||
|
|
||||||
|
if (alloc != Many && dealloctype != No && dealloctype != Many && dealloctype != alloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
alloctype = alloc;
|
alloctype = alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,8 +466,11 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
if (dealloc != No)
|
if (dealloc != No)
|
||||||
{
|
{
|
||||||
addtoken("dealloc");
|
addtoken("dealloc");
|
||||||
if ((alloctype != No && alloctype != dealloc) ||
|
|
||||||
(dealloctype != No && dealloctype != dealloc))
|
if (dealloctype != No && dealloctype != dealloc)
|
||||||
|
dealloc = Many;
|
||||||
|
|
||||||
|
if (dealloc != Many && alloctype != No && alloctype != Many && alloctype != dealloc)
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, varname);
|
||||||
|
@ -1457,14 +1464,17 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
|
||||||
AllocType alloc = GetAllocationType(tok->tokAt(2));
|
AllocType alloc = GetAllocationType(tok->tokAt(2));
|
||||||
if (alloc != No)
|
if (alloc != No)
|
||||||
{
|
{
|
||||||
|
if (Alloc != No && Alloc != alloc)
|
||||||
|
alloc = Many;
|
||||||
|
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
if ((Dealloc != No && Dealloc != alloc) ||
|
if (alloc != Many && Dealloc != No && Dealloc != Many && Dealloc != alloc)
|
||||||
(Alloc != No && Alloc != alloc))
|
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
Alloc = alloc;
|
Alloc = alloc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1481,14 +1491,17 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
|
||||||
}
|
}
|
||||||
if (dealloc != No)
|
if (dealloc != No)
|
||||||
{
|
{
|
||||||
|
if (Dealloc != No && Dealloc != dealloc)
|
||||||
|
dealloc = Many;
|
||||||
|
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
if ((Dealloc != No && Dealloc != dealloc) ||
|
if (dealloc != Many && Alloc != No && Alloc != Many && Alloc != dealloc)
|
||||||
(Alloc != No && Alloc != dealloc))
|
|
||||||
{
|
{
|
||||||
callstack.push_back(tok);
|
callstack.push_back(tok);
|
||||||
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
ErrorMessage::mismatchAllocDealloc(_errorLogger, _tokenizer, callstack, FullVariableName.str());
|
||||||
callstack.pop_back();
|
callstack.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
Dealloc = dealloc;
|
Dealloc = dealloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum AllocType { No, Malloc, gMalloc, New, NewArray, FOPEN, POPEN };
|
/** What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */
|
||||||
|
enum AllocType { No, Malloc, gMalloc, New, NewArray, FOPEN, POPEN, Many };
|
||||||
|
|
||||||
// Extra allocation..
|
// Extra allocation..
|
||||||
class AllocFunc
|
class AllocFunc
|
||||||
|
|
|
@ -120,8 +120,8 @@ private:
|
||||||
TEST_CASE(ret5); // Bug 2458436 - return use
|
TEST_CASE(ret5); // Bug 2458436 - return use
|
||||||
|
|
||||||
TEST_CASE(mismatch1);
|
TEST_CASE(mismatch1);
|
||||||
// TODO TEST_CASE(mismatch2);
|
TEST_CASE(mismatch2);
|
||||||
// TODO TEST_CASE(mismatch3);
|
TEST_CASE(mismatch3);
|
||||||
TEST_CASE(mismatch4);
|
TEST_CASE(mismatch4);
|
||||||
|
|
||||||
TEST_CASE(func1);
|
TEST_CASE(func1);
|
||||||
|
@ -1013,8 +1013,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" delete [] p;\n"
|
" delete [] p;\n"
|
||||||
"}\n", false);
|
"}\n", false);
|
||||||
ASSERT_EQUALS(std::string("[test.cpp:6]: (all) Mismatching allocation and deallocation: p\n"
|
ASSERT_EQUALS(std::string("[test.cpp:6]: (all) Mismatching allocation and deallocation: p\n"), errout.str());
|
||||||
"[test.cpp:9]: (all) Mismatching allocation and deallocation: p\n"), errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue