Fixed #3303 (false positive: memory leak (reference count))
This commit is contained in:
parent
522da8d258
commit
39af75abb4
|
@ -2563,6 +2563,10 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
|
|||
std::string temp = "this . " + varname;
|
||||
dealloc = getDeallocationType(tok, temp);
|
||||
}
|
||||
// some usage in the destructor => assume it's related
|
||||
// to deallocation
|
||||
if (destructor && tok->str() == varname)
|
||||
dealloc = CheckMemoryLeak::Many;
|
||||
if (dealloc != CheckMemoryLeak::No) {
|
||||
if (destructor)
|
||||
deallocInDestructor = true;
|
||||
|
|
|
@ -3812,6 +3812,7 @@ private:
|
|||
TEST_CASE(class20);
|
||||
TEST_CASE(class21); // ticket #2517
|
||||
TEST_CASE(class22); // ticket #3012
|
||||
TEST_CASE(class23); // ticket #3303
|
||||
|
||||
TEST_CASE(staticvar);
|
||||
|
||||
|
@ -4695,6 +4696,25 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void class23() { // ticket #3303 - false positive
|
||||
check("class CDataImpl {\n"
|
||||
"public:\n"
|
||||
" CDataImpl() { m_refcount = 1; }\n"
|
||||
" void Release() { if (--m_refcount == 0) delete this; }\n"
|
||||
"private:\n"
|
||||
" int m_refcount;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class CData {\n"
|
||||
"public:\n"
|
||||
" CData() : m_impl(new CDataImpl()) { }\n"
|
||||
" ~CData() { if (m_impl) m_impl->Release(); }\n"
|
||||
"private:\n"
|
||||
" CDataImpl *m_impl;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void staticvar() {
|
||||
check("class A\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue