diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index cc8b6853f11..d4024865dc1 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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()) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 783a10ad089..cd6249ab3d3 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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() {