Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex eating up memory.

Status
Not open for further replies.

kama1

Programmer
Aug 5, 2001
5
SE
Hi, ive written a regex function using regex.h this is the code.

int match_reg(char * regpattern)
{
regex_t rgx;
int status;
char * tempo;

len = strlen(buffer);
tempo = new char[len + 1];
strcpy(tempo, buffer);

if ( regcomp( &rgx, regpattern, REG_EXTENDED|REG_NOSUB ) != 0 )
{
cout << &quot;regcomp failed&quot; << endl;
return(1);
}


if ( status = regexec( &rgx, tempo, 0, NULL, 0) == 0 )
{
delete [] tempo;
//delete [] regpattern;
return(1);
} else {
delete [] tempo;
//delete [] regpattern;
return(0);
}
}

but for some reason it eating up all my memory and eventually it will seq fault.

the code runs fine without the match_reg() call. as soon as i call it, the memory usage goes up. I do nothing except calling this function alot of times, aprox 50000 times.

Any idea where the fault is?

/Bjorn
 
Ah.. found out why.. =) forgot to add regfree(&rgx)

Have to blame that i wrote it at 2 am.. =)

/Bjorn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top