Tests: Added "testmemcheck4", memory leak from a strdup
This commit is contained in:
parent
c3efd64b27
commit
9523f0e2e8
4
main.cpp
4
main.cpp
|
@ -699,7 +699,7 @@ void CreateStatementList()
|
||||||
if ( ismalloc )
|
if ( ismalloc )
|
||||||
AppendStatement(STATEMENT::MALLOC, tok2, varname);
|
AppendStatement(STATEMENT::MALLOC, tok2, varname);
|
||||||
|
|
||||||
if ( match(rs,"new type ;") )
|
else if ( match(rs,"new type ;") )
|
||||||
AppendStatement(STATEMENT::NEW, tok2, varname);
|
AppendStatement(STATEMENT::NEW, tok2, varname);
|
||||||
|
|
||||||
else if ( match(rs, "new type (") )
|
else if ( match(rs, "new type (") )
|
||||||
|
@ -1128,7 +1128,7 @@ void CheckMemoryLeak()
|
||||||
if (varlist[i]->indentlevel != indentlevel)
|
if (varlist[i]->indentlevel != indentlevel)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (varlist[i]->value == _variable::New || varlist[i]->value == _variable::NewA)
|
if (varlist[i]->value == _variable::Malloc || varlist[i]->value == _variable::New || varlist[i]->value == _variable::NewA)
|
||||||
{
|
{
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << FileLine(it->Token) << ": Memory leak:" << VariableNames[varlist[i]->varindex];
|
ostr << FileLine(it->Token) << ": Memory leak:" << VariableNames[varlist[i]->varindex];
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
[testmemcheck4\testmemcheck4.cpp:10]: Memory leak:str
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
|
||||||
|
void f()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < j; i++)
|
||||||
|
{
|
||||||
|
char *str = strdup("hello");
|
||||||
|
if (condition)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue