applegrew 15 Newbie Poster

(I have 2 queries)

I have made a html parser but the memory leaks, as it seems from the message below; is killing me. I am getting this message from gdb debugger (cygwin build).

Heap block at 003D2CA0 modified at 003D2CB3 past requested size of b


Also now not all the output from cout and printf are getting printed. I am posted the code of main() function where all the pointer acrobatics takes place. The class Parser does the parsing. It can parse from a file or from a character array. It uses an object (buf) of vector<char> to store the output and dynamically instructs vector to resizes when needed using the code...

if(bufptr>=buf.size()) buf.resize(buf.size()+INITIAL_BUF_SIZE,'\0');
buf[bufptr++]=c;

Query 1: What is the difference between vector's resize and reserve?

Quer 2: Do u see any possible memory leaks in the badly hacked code below?

int main(){
    Parser p;
    Tag tag;
    strcpy(tag.name,"div");
    
    Property *px=new Property[2];
    strcpy(px[0].name,"id");
    strcpy(px[0].value,"res");
    tag.totalProperties=1;
    tag.property=px;
    
    bool err;
    char *out=p.parse("g-ogre.htm",tag,0,NULL,0,err,true);
    //cout<<"div:: "<<out<<endl;
    
    
    strcpy(tag.name,"p");
    tag.totalProperties=0;
    
    char *tout=p.parse(out,tag,1,NULL,0,err,false);
    //cout<<tout<<endl;
    
    strcpy(tag.name,"a");
    char *rp=new char[300], *trp=NULL;
    rp[0]='\0';
    int i=1;
    do{
        if(trp) {delete [] trp; trp=NULL;}
        trp=p.parse(tout,tag,i++,NULL,0,err,false);
        strcat(rp,"; ");
        strcat(rp,trp);
    }while(strLen(trp)!=0);
    if(trp) {delete [] trp; trp=NULL;}
    if(tout) {delete [] tout; tout=NULL;}
    //cout<<"Related phrases::-\n"<<rp<<endl;
    
    strcpy(tag.name,"ul");
    strcpy(px[0].name,"type");
    strcpy(px[0].value,"disc");
    tag.totalProperties=1;
    
    Tag itag;//tags to ignore.
    strcpy(itag.name,"br");
    //strcpy(itag[0].name,"a");
    
    tout=p.parse(out,tag,1,&itag,1,err);
    //cout<<"ul :: "<<tout<<endl;
    
    tag.totalProperties=0;
    char *lp=new (nothrow) char[10000];
    if(lp==NULL){
        cout<<"Out of Memory!!!"<<endl;
        return 0;
    }
    lp[0]='\0';
    lp[9999]='@';
    i=1;
    trp=NULL;
    strcpy(itag.name,"a");
    do{
        if(trp) {delete [] trp; trp=NULL;}
        strcpy(tag.name,"font");
        trp=p.parse(tout,tag,i++,NULL,0,err);
        if(strLen(trp)==0) break;
        strcat(lp,"\n\n:");
        char *qp=NULL; …
Ancient Dragon commented: Thanks for taking the time to learn how to use code tags +15