From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: fix PR 9350
Date: Wed, 07 Jan 2009 08:35:00 -0000 [thread overview]
Message-ID: <20090107083448.GJ3664@adacore.com> (raw)
In-Reply-To: <m3sknv7wj8.fsf@fleche.redhat.com>
Hi Tom,
> This patch fixes PR 9350, a memory leak in gdb.
[...]
> I think most of the fixes are pretty obvious in context. They are
> largely cases of forgetting to run cleanups.
This is actually something that I learnt only relatively recently,
maybe a year or two ago: If you put something on the cleanup queue,
you should perform the cleanup when you're done, or you run
the risk of having a memory leak.
But the only case so far where this happens in the following
scenario:
function_b ()
{
temp_memory = xmalloc (...);
make_cleanup (xfree, temp_memory);
[...] // Function returns without having performed the cleanup
}
function_a ()
{
permanent_memory = xmalloc (...);
old_chain = make_cleanup (xfree, permanent_memory);
[...]
if (everything_ok)
discard_cleanups (old_chain);
else
do_cleanups (old_chain);
}
Do we have a different scenario in your example that causes
a memory leak?
> @@ -2309,14 +2317,14 @@ print_it_typical (bpstat bs)
> (uiout, "reason",
> async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER));
> mention (b);
> - ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
> + make_cleanup_ui_out_tuple_begin_end (uiout, "value");
> ui_out_text (uiout, "\nOld value = ");
> watchpoint_value_print (bs->old_val, stb->stream);
> ui_out_field_stream (uiout, "old", stb);
> ui_out_text (uiout, "\nNew value = ");
> watchpoint_value_print (b->val, stb->stream);
> ui_out_field_stream (uiout, "new", stb);
> - do_cleanups (ui_out_chain);
> + do_cleanups (old_chain);
> ui_out_text (uiout, "\n");
> /* More than one watchpoint may have been triggered. */
> return PRINT_UNKNOWN;
Ooops, does it look like you're using uiout after it has been
deleted? (I have seen the same issue a few more time later
in your patch)
Perhaps this function would benefit from having only one place
where the result is returned, thus requiring only one call to
do_cleanups? At first sight, it seems relatively easy to achieve
in this case. That's an open question - I'm fine with just fixing
the above by moving the do_cleanups to just before the return.
> @@ -5441,8 +5452,10 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
>
> if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
> {
> + struct expression *expr;
> tok = cond_start = end_tok + 1;
> - parse_exp_1 (&tok, block_for_pc (pc), 0);
> + expr = parse_exp_1 (&tok, block_for_pc (pc), 0);
> + xfree (expr);
> cond_end = tok;
> *cond_string = savestring (cond_start,
> cond_end - cond_start);
Would you mind adding an empty line after the declaration of
variable expr? I have to admit that I am not sure whether this
is a written rule of the GDB coding style, but Mark often commented
on this, and I think it helps structuring the code a bit.
[I think we should have a place in our documentation where this is
explicitly spelled out - it could be our Wiki, or gdbint. But that's
a separate thread].
The rest looked good to me.
--
Joel
next prev parent reply other threads:[~2009-01-07 8:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 1:08 Tom Tromey
2009-01-07 8:35 ` Joel Brobecker [this message]
2009-01-07 14:49 ` Tom Tromey
2009-01-07 16:18 ` Tom Tromey
2009-01-08 9:27 ` Joel Brobecker
2009-01-08 16:33 ` Tom Tromey
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=20090107083448.GJ3664@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@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