Fixed #2317 ((style) Variable is allocated memory that is never used)
This commit is contained in:
parent
cdc8801be0
commit
f73cce9eca
|
@ -1641,6 +1641,9 @@ void CheckOther::functionVariableUsage()
|
||||||
else if (var && var->_type == Variables::pointer &&
|
else if (var && var->_type == Variables::pointer &&
|
||||||
Token::Match(start, "%var% = new|malloc|calloc|g_malloc|kmalloc|vmalloc"))
|
Token::Match(start, "%var% = new|malloc|calloc|g_malloc|kmalloc|vmalloc"))
|
||||||
{
|
{
|
||||||
|
if (start->strAt(2) == "new" && !start->tokAt(3)->isStandardType())
|
||||||
|
variables.write(varid1);
|
||||||
|
else
|
||||||
variables.allocateMemory(varid1);
|
variables.allocateMemory(varid1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -2550,11 +2550,19 @@ private:
|
||||||
|
|
||||||
functionVariableUsage("void foo()\n"
|
functionVariableUsage("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" string* txt = new string(\"test\");\n"
|
" Fred* fred = new Fred;\n"
|
||||||
" std::cout << \"test\" << std::endl;\n"
|
" std::cout << \"test\" << std::endl;\n"
|
||||||
" delete txt;\n"
|
" delete fred;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'txt' is allocated memory that is never used\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" Fred* fred = malloc(sizeof(Fred));\n"
|
||||||
|
" std::cout << \"test\" << std::endl;\n"
|
||||||
|
" free(fred);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'fred' is allocated memory that is never used\n", errout.str());
|
||||||
|
|
||||||
|
|
||||||
functionVariableUsage("void foo()\n"
|
functionVariableUsage("void foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue