From 6b48781fdc1e13b077d3299b7c87fa76ecab0a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 7 Jul 2017 21:51:48 +0200 Subject: [PATCH] Fixed #7105 (False positive resourceLeak - socket handle wiped after close) --- lib/checkleakautovar.cpp | 3 +++ test/testleakautovar.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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"