diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 8e260fb24..cb2876eef 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 1169e1954..b7435ce6d 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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; } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index a88b53e22..475743c34 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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 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"