Skip to content
Merged
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
3 changes: 3 additions & 0 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,9 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop
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 &&
Expand Down
15 changes: 15 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,21 @@ class TestMemleakNoVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:2:19]: (error) Allocation with new, strlen doesn't release it. [leakNoVarFunctionCall]\n"
"[test.cpp:5:20]: (error) Allocation with new, strlen doesn't release it. [leakNoVarFunctionCall]\n",
errout_str());

check("int* f1() { return new int; }\n" // #14808
"std::string* f2() { return new std::string(\"abc\"); }\n"
"std::clock_t* f3() { return new std::clock_t; }\n"
"QWidget* f4(QObject* parent) { return new QWidget(parent); }\n"
"void g(QObject* parent) {\n"
" assert(f1());\n"
" assert(f2());\n"
" assert(f3());\n"
" assert(f4(parent));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6:12]: (error) Allocation with f1, assert doesn't release it. [leakNoVarFunctionCall]\n"
"[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());
}

void missingAssignment() {
Expand Down
Loading