diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index f2bc989ed..c7b17bf78 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -571,6 +571,9 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const Va arg = arg->tokAt(5); } + while (Token::Match(arg, "%var% . %var%")) + arg = arg->tokAt(2); + if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var%")) { // goto variable if (arg->str() == "&") diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 68cb5c5d5..4cbe915b8 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -76,6 +76,9 @@ private: TEST_CASE(exit2); TEST_CASE(exit3); + // handling function calls + TEST_CASE(functioncall1); + // goto TEST_CASE(goto1); TEST_CASE(goto2); @@ -894,6 +897,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void functioncall1() { + check("void f(struct S *p) {\n" + " p->x = malloc(10);\n" + " free(p->x);\n" + " p->x = 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void goto1() { check("static void f() {\n" " int err = -ENOMEM;\n"