Mail Archives: djgpp/1999/12/10/18:00:47
Eli Zaretskii schrieb in Nachricht ...
>
>On Thu, 9 Dec 1999, Wormy wrote:
>
>> But if, at shutdown, I do
>>
>> for (x=0; x<4096; x++)
>> if (mem[x] != NULL)
>> free (mem[x]);
>>
>> IT HAPPENS... WELL, MORE THAN ONLY SOMETIMES THAT I GET A SIGSEGV!!!!!
>> WHY IS THAT???
>
>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??!
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!
Funny thing is it happens even if I check if mem[i] != NULL ----> So the
program shouldn't free any memory that wasn't freed yet...
Could it be a bug with DJGPP or is it maybe my computer?
Hm... maybe I should test it on several computers?
- Raw text -