This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

malloc()/free() help,please


Overall I really,really like this package!  (OTOH plain text man pages, or a simple man tool would REALLY be good....)   But I have a small problem.  A simple tool I wrote that works find on Unix is blowing up in free():

This reads in a dictionary "filename", constructed of

"Lanuage-A", "Language-B"

pairs.  I want to be able to call the  program and reload
the dictionary at will, however the third time (not the first,   
or the second) it blows up doing a free() - not in Unix, only in  
the cygwin gcc compiled version on my W95 box:
   
Any thoughts:

int read_dict(char *filename){
    FILE *RD;
    int x;
    char *ecop,*gcop;



    for (x=0;x<wcount;x++){
        free(voc[x][ENG]);
        free(voc[x][GAL]);
    }

    wcount = 0;

    if (RD = fopen(filename,"r")){

        while ( fgets (input,2000,RD) ){
  
            e = strchr(input,'\"');

            e++; /*now we have the english word*/

            g = strchr(e,'\"');
            
            *g = (char)0; /*null out end of eng word*/
            
            g++;

            g = strchr(g,'\"');

            g++; /*now we have start of galactic word*/

            i = strchr(g,'\"');

            *i = (char)0; /*null out end of gal word*/
            /*  printf ("G: >%s< / E: >%s<\n",g,e);*/
            ecop = (char*)malloc(strlen(e));
            gcop = (char*)malloc(strlen(g));
            strcpy(ecop,e);
            strcpy(gcop,g);
            voc[wcount][ENG]=ecop;
            voc[wcount][GAL]=gcop;
            wcount++;
        }
     
    }
    
    return wcount;
}




            
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]