From: Dave Allan <da_gdb@egenera.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: gdb@sources.redhat.com
Subject: Re: execute_control_command may not remove its cleanups
Date: Thu, 19 Feb 2004 19:14:00 -0000 [thread overview]
Message-ID: <1077217836.1304.1361.camel@hasufel.egenera.com> (raw)
In-Reply-To: <20040219184730.GA26281@nevyn.them.org>
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.
Dave
On Thu, 2004-02-19 at 13:47, Daniel Jacobowitz wrote:
> On Thu, Feb 19, 2004 at 01:21:52PM -0500, Dave Allan wrote:
> > > > However, it seems from code inspection and the gdb internals
> > > > documentation that the call to do_cleanups ought to be unconditional.
> > > > Does that seem right?
> > >
> > > No, instead, the cleanup chain should always have an item on it. If
> > > make_cleanup is not called then old_chain will remain NULL, and
> > > do_cleanups (NULL) means "do all cleanups", not "do nothing". It looks
> > > to me like command_handler is responsible for there always being a
> > > cleanup on the chain:
> > > old_chain = make_cleanup (null_cleanup, 0);
> > > but maybe I'm mistaken about that; it's a bit far down the tree.
> >
> > I definitely understand that do_cleanups(NULL) will do all cleanups
> > which is not what's wanted here. The call is do_cleanups(old_chain),
> > though, so if there are cleanups on the chain already, they are
> > preserved. The problem isn't the do_cleanups call, it's the fact that
> > the do_cleanups call is conditional. The solution is to remove the if
> > (old_chain) statement and always do the cleanup.
> >
> > Given what's stated in the docs, that a function must always remove the
> > cleanups it creates, it would seem to me that regardless of the state of
> > cleanup_chain at the beginning of execute_control_command, whether it's
> > NULL or contains cleanups, we want to get back to that state before we
> > return.
> >
> > Looking at what cleanups execute_control_command puts on cleanup_chain,
> > that is correct. Either one or two cleanups are put on the chain where
> > arg is an automatic variable and function is free_current_contents. If
> > these cleanups aren't done before the stack frame is destroyed,
> > something undefined will later be freed when the cleanups are done.
>
> Think about this again. Both of those cleanups are conditionally
> created. If neither of them is created, old_chain will still be NULL.
> This will lead to running cleanups prematurely. If the cleanup chain
> is non-empty, things work OK.
>
> The alternative is null_cleanup.
next prev parent reply other threads:[~2004-02-19 19:14 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 [this message]
2004-02-19 22:19 ` Andrew Cagney
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=1077217836.1304.1361.camel@hasufel.egenera.com \
--to=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