grx1042@uoft02.utoledo.edu (Steve Snodgrass) (02/22/90)
In article <1177@mindlink.UUCP>, a218@mindlink.UUCP (Charlie Gibbs) writes: >> for(s=head; s != NULL; s=s->next) free(s); > > > Why take a chance? Being a "belt and suspenders" > [correct program deleted] > A bit of extra work, perhaps, but it's guaranteed > to work even if the OS designer had a bad day. I wouldn't blame it on the OS designer. One should NEVER reference data in memory that has been freed in a multi-tasking system, even immediately after the freeing! Scenario: the wonderful little loop above is hopping along, freeing nodes in a list. It frees, for example, Node 6. This is taking place while you, on your wonderful multi-tasking Amiga, are invoking Sooper Dooper Disk Utility V25.82z to copy some files. Just as Node 6 is freed, the OS grabs some RAM for the disk utility window and copies a bitmap into it. The loop now goes back to the freed Node 6 to find Node 7's address. It happily takes a data value from what is now some window's bitmap, and proceeds to free that address. Say hello to the Guru. This discussion should be moved to c.s.a.tech. +-----------------------------------------------------------------------+ | Reality: Steve Snodgrass <*> Cyberspace: GRX1042 @ UofT02.UToledo.Edu | | /\/ "No his mind is not for rent, to any god or government" -Rush \/\ | | "Mu is the sound a Greek cat makes." -Dr. R.G. Bohn, Univ. of Toledo | `-----------------------------------------------------------------------'