Mail Archives: djgpp/1999/12/12/10:25:17
On Fri, 10 Dec 1999, Wormy wrote:
> >This usually means that your program either overwrites the buffers that
> >you allocate (like if it puts more than 64 bytes into each 64-byte
> >buffer), or that it free()'s some of the buffers more than once.
>
> BUT WHY DOES IT FREE MORE THAN ONCE??!
Most probably, because of bug(s) in your code.
> It even happens sometimes if I execute the following (one after the other):
>
> char *mem[12000];
>
> for (i=0; i<12000; i++) // THIS PART
> ALWAYS WORKS RIGHT ON MY COMP
> //
> THE MEMORIES ARE PROPERLY ALLOCATED I CAN
> //
> WRITE AND READ TO THEM
> {
> if ((mem[i]=(char *)malloc(64*sizeof(char)))==NULL)
> HANDLE ERROR
> else
> memset(mem[i], 0, 64*sizeof(char));
> }
>
> // AND NOW WITHOUT DOING ANYTHING
>
> for (i=0; i<12000; i++)
> {
> if (mem[i] != NULL)
> free (mem[i]);
> }
>
> // AND SOMETIMES IT HAPPENS THAT THE PROGRAM SHUTS DOWN WITH A SIGSEGV!
Please post the smallest complete program that can be compiled and
used to reproduce these problems on your machine. It is very hard to
help you without seeing the complete program. I'm guessing that the
buggy code is somewhere in the fragments that you omitted.
- Raw text -