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 << "regcomp failed" << 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
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 << "regcomp failed" << 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