Skip to content

Commit 09d0cc4

Browse files
author
Aaron Danen
committed
Fix #14949: FP when passing resource to ctor
1 parent 8effc6c commit 09d0cc4

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/checkmemoryleak.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void CheckMemoryLeakInClassImpl::check()
517517
// only check classes and structures
518518
for (const Scope * scope : symbolDatabase->classAndStructScopes) {
519519
for (const Variable &var : scope->varlist) {
520-
if (!var.isStatic() && (var.isPointer() || var.isPointerArray())) {
520+
if (!var.isStatic()) {
521521
// allocation but no deallocation of private variables in public function..
522522
const Token *tok = var.typeStartToken();
523523
// Either it is of standard type or a non-derived type
@@ -1046,7 +1046,8 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop
10461046
const AllocType alloc = getAllocationType(arg, 0);
10471047
if (alloc == No)
10481048
continue;
1049-
if (alloc == New || alloc == NewArray) {
1049+
//if (alloc == New || alloc == NewArray) {
1050+
else {
10501051
const Token* typeTok = arg->next();
10511052
bool bail = !typeTok->isStandardType() &&
10521053
(!typeTok->valueType() ||

test/testmemleak.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,23 @@ class TestMemleakNoVar : public TestFixture {
26282628
"[test.cpp:7:12]: (error) Allocation with f2, assert doesn't release it. [leakNoVarFunctionCall]\n"
26292629
"[test.cpp:8:12]: (error) Allocation with f3, assert doesn't release it. [leakNoVarFunctionCall]\n",
26302630
errout_str());
2631+
check("struct S {\n"
2632+
" explicit S(int fd) {\n"
2633+
" m_fd = fd;\n"
2634+
" }\n"
2635+
" ~S() {\n"
2636+
" if (m_fd >= 0)\n"
2637+
" close(m_fd); \n"
2638+
" }\n"
2639+
" int m_fd = -1;\n"
2640+
"};\n"
2641+
"S g(char *name) {\n"
2642+
" return S(mkostemp(name, 0));\n"
2643+
"}\n"
2644+
"void f(char* ptr) {\n"
2645+
" S s = g(ptr);\n"
2646+
"}\n");
2647+
ASSERT_EQUALS("", errout_str());
26312648
}
26322649

26332650
void missingAssignment() {

0 commit comments

Comments
 (0)