Fixed #5923 (false positive: (error) Resource leak: fp (static file pointer))

This commit is contained in:
Daniel Marjamäki 2014-06-23 16:05:28 +02:00
parent 0a17473962
commit 1ae6531c4c
2 changed files with 11 additions and 1 deletions

View File

@ -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;
}

View File

@ -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"