Mail Archives: djgpp/2003/03/03/03:15:12
Sergio Aguayo <sergioag AT ec-red DOT com> wrote in message
news:3E62BFC8 DOT 4E12DED8 AT ec-red DOT com...
> No, i'm declaring an array of pointers:
>
> char *pcode[20];
>
> then i allocate memory for each one in a "for" as follows:
>
> pcode[i] = (char*)malloc(length of file to load);
>
> when i finish, i call:
>
> free(pcode[i]);
That is in a for loop, isn't it?
>
> there's where the SIGSEGV occurs.
>
> Sergio
>
Check that your reads are not larger than your buffers. If they are, then
they could be overwriting the 16 bytes between mallocs. I think that these
16 bytes tell free() how big the buffer is, as well as some other stuff.
What about if you added all of the filelengths together, added 80 bytes to
that, and then malloc()'d that space. Then use the first 80 bytes for the
pointer array. Then set each pointer in the array to the right position
within the buffer, so that each pointer points the [length of the previous
file] after the pointer to the previous file. When you're finished, all you
have to do is free() the pointer array, which will automatically free your
entire buffer.
- Raw text -