Fixed #2056 (False positive: Resource leak)

This commit is contained in:
Daniel Marjamäki 2010-09-19 12:16:29 +02:00
parent a6ff3681bb
commit 78bd66cd5c
2 changed files with 17 additions and 8 deletions

View File

@ -1983,13 +1983,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// use; if return; dealloc; => if return; dealloc;
if (Token::Match(tok2, "[;{}] use ; if return ; dealloc ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(3));
done = false;
}
// Delete first part in "use ; return use ;"
if (Token::Match(tok2, "[;{}] use ; return use ;"))
{

View File

@ -310,6 +310,7 @@ private:
TEST_CASE(func16);
TEST_CASE(func17);
TEST_CASE(func18);
TEST_CASE(func19); // Ticket #2056 - if (!f(p)) return 0;
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
@ -752,7 +753,7 @@ private:
ASSERT_EQUALS("; alloc ; if dealloc ; dealloc ;", simplifycode("; alloc ; if { dealloc ; } dealloc ;"));
// use ; dealloc ;
ASSERT_EQUALS("; alloc ; if return ; dealloc ;", simplifycode("; alloc ; use ; if { return ; } dealloc ;"));
ASSERT_EQUALS("; alloc ; use ; if return ; dealloc ;", simplifycode("; alloc ; use ; if { return ; } dealloc ;"));
}
@ -1670,6 +1671,21 @@ private:
ASSERT_EQUALS("", errout.str());
}
void func19()
{
// Ticket #2056
check("bool a(int *p) {\n"
" return p;\n"
"}\n"
"\n"
"void b() {\n"
" int *p = malloc(16);\n"
" if (!a(p)) return;\n"
" free(p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}