From 41b624230fb270cc920c7ef071225ef3815d6700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Aug 2012 17:02:11 +0200 Subject: [PATCH] Fixed #3942 (false positive: (error) Memory leak: keyword) --- lib/checkleakautovar.cpp | 2 ++ test/testleakautovar.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 985e9a25e..5a804189a 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -506,6 +506,8 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const st } else if (!dealloc.empty()) { alloctype[arg->varId()] = "dealloc"; } + } else if (Token::Match(arg, "%var% (")) { + functionCall(arg, varInfo, dealloc); } } } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 97bd72da7..1cc8df872 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -43,6 +43,7 @@ private: TEST_CASE(assign8); TEST_CASE(assign9); TEST_CASE(assign10); + TEST_CASE(assign11); // #3942: x = a(b(p)); TEST_CASE(deallocuse1); TEST_CASE(deallocuse2); @@ -201,6 +202,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void assign11() { // #3942 - FP for x = a(b(p)); + check("void f() {\n" + " char *p = malloc(10);\n" + " x = a(b(p));\n" + "}"); + ASSERT_EQUALS("[test.c:4]: (information) b configuration is needed to establish if there is a leak or not\n", errout.str()); + } + void deallocuse1() { check("void f(char *p) {\n" " free(p);\n"