Fix #9781 FP deallocuse after auto_ptr (#3724)

This commit is contained in:
chrchr-github 2022-01-19 21:39:45 +01:00 committed by GitHub
parent 19f605c7e5
commit 4d44d0c079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -2136,13 +2136,6 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
return false;
}
static bool isVariableChangedByFunctionCall(const Token* tok, int indirect, const Settings* settings)
{
bool inconclusive = false;
bool r = isVariableChangedByFunctionCall(tok, indirect, settings, &inconclusive);
return r || inconclusive;
}
bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, bool cpp, int depth)
{
if (!tok)

View File

@ -836,7 +836,7 @@ void CheckLeakAutoVar::changeAllocStatus(VarInfo *varInfo, const VarInfo::AllocI
var->second.type = allocation.type;
var->second.allocTok = allocation.allocTok;
}
} else if (allocation.status != VarInfo::NOALLOC) {
} else if (allocation.status != VarInfo::NOALLOC && allocation.status != VarInfo::OWNED) {
alloctype[arg->varId()].status = VarInfo::DEALLOC;
alloctype[arg->varId()].allocTok = tok;
}

View File

@ -101,6 +101,7 @@ private:
TEST_CASE(deallocuse6); // #4034: FP. x = p = f();
TEST_CASE(deallocuse7); // #6467, #6469, #6473
TEST_CASE(deallocuse8); // #1765
TEST_CASE(deallocuse9); // #9781
TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
@ -696,6 +697,15 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
}
void deallocuse9() { // #9781
check("void f(Type* p) {\n"
" std::shared_ptr<Type> sp(p);\n"
" bool b = p->foo();\n"
" return b;\n"
"}\n", /*cpp*/ true);
ASSERT_EQUALS("", errout.str());
}
void doublefree1() { // #3895
check("void f(char *p) {\n"
" if (x)\n"