On Fri, 10 Jun 2005 19:20:00 +0000, Mark wrote:
"Martin Ambuhl" <ma*****@earthlink.net> wrote in message
news:oU*****************@newsread1.news.atl.earthl ink.net... AC wrote: Is the following code valid?
It is not valid C89 (C90); it is valid C99.
*May* be valid C99... depends on return from malloc() which is not checked.
Quick question:
cfaq question 7.24 (relating to whether allocated memory must be freed prior
to exit)
references a section 7.10.3.2 no longer existant (AFAICT) in the current
standard...
So what's the official take? Answer remains the same but unsubstantiated?
The C language has never required you to free memory before the program
terminates - strictly conforming programs do not need to do this.
The standard is concerned about the behaviour of a program while it is
executing up to the point it generates a termination status. What happens
after it terminates is of no concern to the standard. In particular it has
nothing to say about the reclamation of any of the resources that the
program used. That includes memory allocated for code, automatic objects,
static objects, allocated objects that have been freed, allocated objects
that have not been freed, and anything else that the implementation uses
to support the execution of the program.
Whether these things are reclaimed or not is therefore an implementation
issue. You may take a view that freed objects are more likely to be
reclaimed than unfreed ones, but there's nothing in the standard to
support that view, and very little evidence from real-world
implementations either. The fact is that a implementation that doesn't
reclaim fully will have resource leak and therefore stability issues
that are rarely if ever acceptable.
Perhaps a more solid reason for freeing memory before the program
terminates is to help debugging tools such as memory leak detectors.
Lawrence