l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 May 08 18:46

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Must one free() in C?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Must one free() in C?

On Wed, 8 May 2002, Jeff Newmiller wrote:

> On Wed, 8 May 2002, Mark K. Kim wrote:
> [...]
> > The impliciation of requiring calls to free() before
> > exitting is enormous -- one would have to keep track of all the allocated
> > memory before exitting from any error condition!
> Are you complaining? :)

If I understand you correctly, one must call free() on all allocated
memory before exitting the program.  That means you can't exit simply
because you ran out of memory because first you must *free* all memory
first;  you can't exit because of a failed assertion test -- because first
you must free all memory first; and you can't exit from a program because
you got a signal that can't be handled any further -- because you first
must free all memory first!  That's rediculous!

If the above is true, I think the better question is "why aren't *you*

The system (whether that be the OS or the C library) obviously knows of
all its memory and how they're allocated; if it didn't, free() wouldn't
know how much memory to free when you call free() on a pointer.  So it's
got a list of allocated memory *somewhere*, so why can't *it* handle
freeing all the memory upon exit?  If freeing memory is *required*, then
the system, designed to make the programmers' lives easier, should be the
one doing the freeing, not the programmer!

If what you're saying is true, I'd be writing malloc(), calloc(), and
realloc() wrappers -- the ultimate set of functions that keeps track of
all the allocated memory and calls itself on exit() (using atexit()) to
free all memory.  That's very generic, it's platform-independent, and
there's no more or less overhead than a specialized one (for the most
part).  The question then is, why doesn't the C standard say this easy
thing can't be implemented by the system and has to be implemented by the

Mark "Jeff's-gotta-be-wrong" Kim
[homepage address removed in fear for personal safety]
PGP key available upon request to only closest relatives.

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!