Memory Leak: Fixed bug with strdup in loop. Bug 2225370
This commit is contained in:
parent
c220b061dc
commit
db6b4b3069
|
@ -234,6 +234,8 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
AllocType alloctype = No;
|
||||
AllocType dealloctype = No;
|
||||
|
||||
bool isloop = false;
|
||||
|
||||
int indentlevel = 0;
|
||||
int parlevel = 0;
|
||||
for ( ; tok; tok = tok->next )
|
||||
|
@ -255,6 +257,7 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
parlevel++;
|
||||
else if ( tok->str[0] == ')' )
|
||||
parlevel--;
|
||||
isloop &= ( parlevel > 0 );
|
||||
|
||||
if ( parlevel == 0 && tok->str[0]==';')
|
||||
addtoken(";");
|
||||
|
@ -332,7 +335,12 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
|
|||
|
||||
// Loops..
|
||||
if (Match(tok, "for") || Match(tok, "while") || Match(tok, "do") )
|
||||
{
|
||||
addtoken("loop");
|
||||
isloop = Match(tok, "%var% (");
|
||||
}
|
||||
if ( isloop && Match(tok,"%var1%",varnames) )
|
||||
addtoken("!var");
|
||||
|
||||
// continue / break..
|
||||
if ( Match(tok, "continue") )
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
TEST_CASE( forwhile2 );
|
||||
TEST_CASE( forwhile3 );
|
||||
TEST_CASE( forwhile4 );
|
||||
TEST_CASE( forwhile5 );
|
||||
|
||||
TEST_CASE( switch1 );
|
||||
TEST_CASE( switch2 );
|
||||
|
@ -374,6 +375,21 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void forwhile5()
|
||||
{
|
||||
check( "void f(const char **a)\n"
|
||||
"{\n"
|
||||
" char *str = 0;\n"
|
||||
" for (int i = 0; i < 10 && !str; ++i)\n"
|
||||
" {\n"
|
||||
" str = strdup(a[i]);\n"
|
||||
" }\n"
|
||||
" return str;\n"
|
||||
"}\n" );
|
||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue