effect of free()

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Sep 14 04:25:51 AEST 1989


In article <gZ3LTWu00Xc8M0Nm0l at andrew.cmu.edu> jdr+ at andrew.cmu.edu (Jeff Rosenfeld) writes:
-> Excerpts from netnews.comp.lang.c: 18-Aug-89 Re: effect of free()
-> jourdan m. joseph at seti.i (1729)
-> >bill at twwells.com (T. William Wells) writes:
-> >> 	free(ptr);
-> >> 	if (ptr == 0) ...
-> >> The if might cause a trap when the value of ptr is accessed.
-> >Not true.  The "if" only examines the value of the pointer, not what it
-> >points to.
-> You're wrong, Dick.  Someone else already pointed it out, but let me
-> make it clear again.  ...
-I can't believe this went so long without a response. Dick is correct;
- at i[you] are mistaken, Jourdan. Keep in mind that pointers are stored in
-memory just like any other data types and can be loaded into
-general-purpose registers. No architecture of which I am aware does
-protection checking when loading data into a general purpose register.

I'm not sure the attributions are correct (this -> >> stuff gets
confusing), but the very mention of "loading into a general-purpose
register" implies a certain limited class of architectures.  The
discussion was about what MIGHT legally occur in a C implementation
on SOME architecture.  And it appears that it is legal for an
implementation to get heartburn over continued access of a pointer
(NOT just of what it presumably would point to) once the associated
storage has been free()d.



More information about the Comp.lang.c mailing list