diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 5b2e6f508..2984d5160 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -374,6 +374,9 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, VarInfo::AllocInfo& varAlloc = alloctype[innerTok->varId()]; varAlloc.type = f->groupId; varAlloc.status = VarInfo::ALLOC; + } else { + // Fixme: warn about leak + alloctype.erase(innerTok->varId()); } } else if (mTokenizer->isCPP() && Token::Match(innerTok->tokAt(2), "new !!(")) { const Token* tok2 = innerTok->tokAt(2)->astOperand1(); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 62acae14d..e5efe782d 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -58,6 +58,8 @@ private: TEST_CASE(assign12); // #4236: FP. bar(&x); // TODO TEST_CASE(assign13); // #4237: FP. char*&ref=p; p=malloc(10); free(ref); TEST_CASE(assign14); + TEST_CASE(assign15); + TEST_CASE(assign16); TEST_CASE(deallocuse1); TEST_CASE(deallocuse2); @@ -311,6 +313,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void assign16() { + check("void f() {\n" + " char *p = malloc(10);\n" + " free(p);\n" + " if (p=dostuff()) *p = 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void deallocuse1() { check("void f(char *p) {\n" " free(p);\n"