cu coredumps
Matthew Dillon
dillon at apollo.backplane.com
Wed Oct 27 11:45:27 PDT 2004
(1) No you cannot safely use data that has been free()'d. Not ever. The
original free() 15+ years ago had the side effect that the last
free()'d data could still be used until the next free(), but nobody
in their right mind programs to that spec any more.
(2) No, you cannot assume that freed data will always cause a seg fault,
or contain good or bad data.
(3) Stop worrying about performance for operations that are executed once
and will take far less then 1 microsecond, and stop worrying about
memory leaks for one-time string operations. Don't worry about
freeing the old data in this case.
(4) Use asprintf(). Do not use malloc+str*() functions. Especially do
not use str*() functions for this sort of thing. Just use asprintf().
-Matt
More information about the Bugs
mailing list