From 1ae6531c4ca2047a229df148e449111d3a27f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 Jun 2014 16:05:28 +0200 Subject: [PATCH] Fixed #5923 (false positive: (error) Resource leak: fp (static file pointer)) --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index c1ed57b98..a27685761 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -220,7 +220,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, // not a local variable nor argument? const Variable *var = tok->variable(); - if (var && !var->isArgument() && !var->isLocal()) { + if (var && !var->isArgument() && (!var->isLocal() || var->isStatic())) { continue; } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 72f70b7f0..6e1c8eb4a 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -95,6 +95,7 @@ private: TEST_CASE(test1); TEST_CASE(test2); TEST_CASE(test3); // #3954 - reference pointer + TEST_CASE(test4); // #5923 - static pointer // Execution reaches a 'throw' TEST_CASE(throw1); @@ -600,6 +601,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void test4() { // 5923 - static pointer + check("void f() {\n" + " static char *p;\n" + " if (!p) p = malloc(10);\n" + " if (x) { free(p); p = 0; }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void throw1() { // 3987 - Execution reach a 'throw' check("void f() {\n" " char *p = malloc(10);\n"