Skip to content

Commit 80d7df0

Browse files
committed
Fixed #8848 (False positive memory leak if locally defined type returns a new pointer)
1 parent 0edf0b5 commit 80d7df0

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
363363
for (const Token *tok2 = func->functionScope->bodyStart; tok2 != func->functionScope->bodyEnd; tok2 = tok2->next()) {
364364
if (const Token *endOfLambda = findLambdaEndToken(tok2))
365365
tok2 = endOfLambda;
366+
if (tok2->str() == "{" && !tok2->scope()->isExecutable())
367+
tok2 = tok2->link();
366368
if (tok2->str() == "return") {
367369
const AllocType allocType = getAllocationType(tok2->next(), 0, callstack);
368370
if (allocType != No)

test/testmemleak.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,15 @@ class TestMemleakNoVar : public TestFixture {
19281928
"}");
19291929
ASSERT_EQUALS("", errout.str());
19301930

1931+
check("void *f() {\n" // #8848
1932+
" struct S { void *alloc() { return malloc(10); } };\n"
1933+
"}\n"
1934+
"void x()\n"
1935+
"{\n"
1936+
" f();\n"
1937+
"}");
1938+
ASSERT_EQUALS("", errout.str());
1939+
19311940
check("void x()\n"
19321941
"{\n"
19331942
" if(!malloc(5)) fail();\n"

0 commit comments

Comments
 (0)