Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,22 +1046,20 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop
const AllocType alloc = getAllocationType(arg, 0);
if (alloc == No)
continue;
if (alloc == New || alloc == NewArray) {
const Token* typeTok = arg->next();
bool bail = !typeTok->isStandardType() &&
(!typeTok->valueType() ||
(typeTok->valueType()->type < ValueType::Type::SMART_POINTER &&
typeTok->valueType()->type != ValueType::Type::POD)) &&
!mSettings.library.detectContainerOrIterator(typeTok) &&
!mSettings.library.podtype(typeTok->expressionString());
if (bail && typeTok->type() && typeTok->type()->classScope &&
typeTok->type()->classScope->numConstructors == 0 &&
typeTok->type()->classScope->getDestructor() == nullptr) {
bail = false;
}
if (bail)
continue;
const Token* typeTok = arg->next();
bool bail = !typeTok->isStandardType() &&
(!typeTok->valueType() ||
(typeTok->valueType()->type < ValueType::Type::SMART_POINTER &&
typeTok->valueType()->type != ValueType::Type::POD)) &&
!mSettings.library.detectContainerOrIterator(typeTok) &&
!mSettings.library.podtype(typeTok->expressionString());
if (bail && typeTok->type() && typeTok->type()->classScope &&
typeTok->type()->classScope->numConstructors == 0 &&
typeTok->type()->classScope->getDestructor() == nullptr) {
bail = false;
}
if (bail)
continue;
if (isReopenStandardStream(arg))
continue;
if (tok->function()) {
Expand Down
17 changes: 17 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,23 @@ class TestMemleakNoVar : public TestFixture {
"[test.cpp:7:12]: (error) Allocation with f2, assert doesn't release it. [leakNoVarFunctionCall]\n"
"[test.cpp:8:12]: (error) Allocation with f3, assert doesn't release it. [leakNoVarFunctionCall]\n",
errout_str());
check("struct S {\n"
" explicit S(int fd) {\n"
" m_fd = fd;\n"
" }\n"
" ~S() {\n"
" if (m_fd >= 0)\n"
" close(m_fd); \n"
" }\n"
" int m_fd = -1;\n"
"};\n"
"S g(char *name) {\n"
" return S(mkostemp(name, 0));\n"
"}\n"
"void f(char* ptr) {\n"
" S s = g(ptr);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void missingAssignment() {
Expand Down
Loading