Fix #12239 FP memleak when passing this in allocation (#5719)

This commit is contained in:
chrchr-github 2023-12-02 14:15:10 +01:00 committed by GitHub
parent ec9dbb31f4
commit ae27b613ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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;

View File

@ -580,6 +580,20 @@ private:
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() {