effect of free()
T. William Wells
bill at twwells.com
Thu Aug 17 10:55:48 AEST 1989
In article <3777 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
: In article <320 at cubmol.BIO.COLUMBIA.EDU> ping at cubmol.UUCP (Shiping Zhang) writes:
: I guess the word is, once space is freed, don't even try to get data
: out of it. It's risky at least, and nonportable without question.
Actually, things are worse than that: once the space is freed, don't
even *look* at the pointer. For example, the following code fragment
is nonportable:
char *ptr;
ptr = malloc(1);
...
free(ptr);
...
if (ptr == 0) ...
The if might cause a trap when the value of ptr is accessed.
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com
More information about the Comp.lang.c
mailing list