Q:

Pointers, running out of memory, segmentation faults?

FILE *fp;
char *in;
char *sa[20];
char inn[100];

//other stuff here

for(huge loop) {
    fp = popen(filename, "r");
    fscanf(fp, "%100s", inn);
    in = strtok(inn, "=");
    i = 0;
    while(in != NULL) {
        sa[i++] = in;
        in = strtok (NULL, "=");
    }
}

This compiles and runs for about 4 minutes on my linux machine, as it sorts through huge data files, and then segmentation faults.  It runs correctly up until this point, and that point changes depending on how much I have it doing, so I strongly suspect a memory leak and that I should be freeing pointers.  But I thought without malloc the compiler allocates and deallocates pointer memory automatically.  What am I doing wrong?
Thanks.

A:

You're leaving no room for a null terminator in the inn array.
There is no pclose for each popen.
You don't check the return value of popen.
There is no guarantee you won't overflow the sa array.

