This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: How much should I cleanup?
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: David Carlton <carlton at math dot stanford dot edu>
- Cc: gdb <gdb at sources dot redhat dot com>
- Date: Sun, 16 Feb 2003 10:22:38 +0100
- Subject: Re: How much should I cleanup?
- References: <ro1d6lygzcs.fsf@jackfruit.Stanford.EDU>
When is it important to make sure that I have cleanups in place? My
understanding is that it's important if I have control of a block of
memory that I want to xfree() after doing some work, but where that
xfree() might not be reached because of exceptional circumstances.
Just assume the exception is the norm - you're going to need to do a
clean-up. The internals doco suggests several conventions.
So, if that's correct: what are 'exceptional circumstances'? I assume
error() and related functions count. I don't know exactly what QUIT
does; do I have to be careful if there are QUIT's in between the
xmalloc() and the xfree()? (Are those the only places where GDB pays
attention to ^C's?) Any other situations?
Failed memory read, no frame.
Sigh. C has its benefits, but ease of memory management isn't one of
them. Every time I have to write a cleanup function, every time I
have to think about whether to alloca() memory for a string or to
xmalloc() it (and every time I can't alloca() it because I'm returning
the string in question), I get another grey hair. (Though the grey
hair falls out soon thereafter, for better or for worse.)
Ah, yes. C++ `is the answer' :-^
David Carlton
carlton@math.stanford.edu
Andrew