From: Andrew Cagney <cagney@gnu.org>
To: da_gdb@egenera.com
Cc: Daniel Jacobowitz <drow@false.org>, gdb@sources.redhat.com
Subject: Re: execute_control_command may not remove its cleanups
Date: Thu, 19 Feb 2004 22:19:00 -0000 [thread overview]
Message-ID: <403530F7.4090609@gnu.org> (raw)
In-Reply-To: <1077217836.1304.1361.camel@hasufel.egenera.com>
Dave,
> Ok. I see your point. How about setting old_chain to cleanup_chain
> unconditionally at the beginning of the function and doing the cleanups
> unconditionally at the end? That way, we're safe against both
> scenarios: against doing cleanups prematurely, but also safe against
> getting into the function with cleanup_chain null and then freeing
> something random at a later point.
FYI, that is one of the ways recommended in the doco:
> The first style is try/finally. Before it exits, your code-block calls
> @code{do_cleanups} with the old cleanup chain and thus ensures that your
> code-block's cleanups are always performed. For instance, the following
> code-segment avoids a memory leak problem (even when @code{error} is
> called and a forced stack unwind occurs) by ensuring that the
> @code{xfree} will always be called:
>
> @smallexample
> struct cleanup *old = make_cleanup (null_cleanup, 0);
> data = xmalloc (sizeof blah);
> make_cleanup (xfree, data);
> ... blah blah ...
> do_cleanups (old);
> @end smallexample
The main reason why the the code you're studying doesn't match the doco
is because it pre-dates that said doco :-(
Andrew
prev parent reply other threads:[~2004-02-19 22:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-19 15:32 Dave Allan
2004-02-19 15:40 ` Daniel Jacobowitz
2004-02-19 18:26 ` Dave Allan
2004-02-19 18:47 ` Daniel Jacobowitz
2004-02-19 19:14 ` Dave Allan
2004-02-19 22:19 ` Andrew Cagney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=403530F7.4090609@gnu.org \
--to=cagney@gnu.org \
--cc=da_gdb@egenera.com \
--cc=drow@false.org \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox