TODO test case realloc5 added and "Checkmemoryleak: simplifycode result for" debug info added.

This commit is contained in:
Reijo Tomperi 2009-08-02 22:23:47 +03:00
parent e0f416e52e
commit 10f6678cf9
2 changed files with 22 additions and 1 deletions

View File

@ -1530,7 +1530,11 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const char varname
} }
simplifycode(tok, all); simplifycode(tok, all);
//tok->printOut("simplifycode result");
if (_settings->_debug)
{
tok->printOut((std::string("Checkmemoryleak: simplifycode result for: ") + varname).c_str());
}
// If the variable is not allocated at all => no memory leak // If the variable is not allocated at all => no memory leak
if (Token::findmatch(tok, "alloc") == 0) if (Token::findmatch(tok, "alloc") == 0)

View File

@ -223,6 +223,7 @@ private:
TEST_CASE(realloc2); TEST_CASE(realloc2);
TEST_CASE(realloc3); TEST_CASE(realloc3);
TEST_CASE(realloc4); TEST_CASE(realloc4);
TEST_CASE(realloc5);
TEST_CASE(assign); TEST_CASE(assign);
@ -1662,6 +1663,22 @@ private:
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str());
} }
void realloc5()
{
check("void foo()\n"
"{\n"
"char *buf;\n"
"char *new_buf;\n"
"buf = calloc( 10 );\n"
"new_buf = realloc ( buf, 20);\n"
"if ( !new_buf )\n"
" free(buf);\n"
"else\n"
" free(new_buf);\n"
"}\n", true);
TODO_ASSERT_EQUALS("", errout.str());
}
void assign() void assign()
{ {