Skip to content

Commit

Permalink
Fix #12239 FP memleak when passing this in allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Dec 2, 2023
1 parent ec9dbb3 commit 8390c6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static bool isLocalVarNoAutoDealloc(const Token *varTok, const bool isCpp)
// non-pod variable
if (isCpp) {
// Possibly automatically deallocated memory
if (isAutoDealloc(var) && Token::Match(varTok, "%var% = new"))
if (isAutoDealloc(var) && Token::Match(varTok, "%var% [=({] new"))
return false;
if (!var->isPointer() && !var->typeStartToken()->isStandardType())
return false;
Expand Down
14 changes: 14 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,20 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n"
"[test.cpp:4]: (error) Memory leak: q\n",
errout.str());

check("struct S : B {\n" // #12239
" void f();\n"
" void g();\n"
"};\n"
"void S::f() {\n"
" FD* fd(new FD(this));\n"
" fd->exec();\n"
"}\n"
"void S::g() {\n"
" FD* fd{ new FD(this) };\n"
" fd->exec();\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}

void isAutoDealloc() {
Expand Down

0 comments on commit 8390c6f

Please sign in to comment.