From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 24/30] Add missing cleanups to defaulted_query and prompt_for_continue
Date: Fri, 18 Mar 2016 19:26:00 -0000 [thread overview]
Message-ID: <1458328714-4938-25-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1458328714-4938-1-git-send-email-palves@redhat.com>
Some of the error paths in these functions leak.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* utils.c (defaulted_query, prompt_for_continue): Free temporary
strings with cleanups, instead of xfree.
---
gdb/utils.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/gdb/utils.c b/gdb/utils.c
index 4d81c23..46f61c1 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1212,6 +1212,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
/* Used to add duration we waited for user to respond to
prompt_for_continue_wait_time. */
struct timeval prompt_started, prompt_ended, prompt_delta;
+ struct cleanup *old_chain;
/* Set up according to which answer is the default. */
if (defchar == '\0')
@@ -1266,13 +1267,16 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
return deprecated_query_hook (ctlstr, args);
}
+ old_chain = make_cleanup (null_cleanup, NULL);
+
/* Format the question outside of the loop, to avoid reusing args. */
question = xstrvprintf (ctlstr, args);
+ make_cleanup (xfree, question);
prompt = xstrprintf (_("%s%s(%s or %s) %s"),
annotation_level > 1 ? "\n\032\032pre-query\n" : "",
question, y_string, n_string,
annotation_level > 1 ? "\n\032\032query\n" : "");
- xfree (question);
+ make_cleanup (xfree, prompt);
/* Used for calculating time spend waiting for user. */
gettimeofday (&prompt_started, NULL);
@@ -1323,9 +1327,9 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
timeval_add (&prompt_for_continue_wait_time,
&prompt_for_continue_wait_time, &prompt_delta);
- xfree (prompt);
if (annotation_level > 1)
printf_filtered (("\n\032\032post-query\n"));
+ do_cleanups (old_chain);
return retval;
}
\f
@@ -1830,6 +1834,7 @@ prompt_for_continue (void)
/* Used to add duration we waited for user to respond to
prompt_for_continue_wait_time. */
struct timeval prompt_started, prompt_ended, prompt_delta;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
gettimeofday (&prompt_started, NULL);
@@ -1852,6 +1857,7 @@ prompt_for_continue (void)
/* Call gdb_readline_wrapper, not readline, in order to keep an
event loop running. */
ignore = gdb_readline_wrapper (cont_prompt);
+ make_cleanup (xfree, ignore);
/* Add time spend in this routine to prompt_for_continue_wait_time. */
gettimeofday (&prompt_ended, NULL);
@@ -1862,7 +1868,7 @@ prompt_for_continue (void)
if (annotation_level > 1)
printf_unfiltered (("\n\032\032post-prompt-for-continue\n"));
- if (ignore)
+ if (ignore != NULL)
{
char *p = ignore;
@@ -1871,7 +1877,6 @@ prompt_for_continue (void)
if (p[0] == 'q')
/* Do not call quit here; there is no possibility of SIGINT. */
throw_quit ("Quit");
- xfree (ignore);
}
/* Now we have to do this again, so that GDB will know that it doesn't
@@ -1879,6 +1884,8 @@ prompt_for_continue (void)
reinitialize_more_filter ();
dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
+
+ do_cleanups (old_chain);
}
/* Initalize timer to keep track of how long we waited for the user. */
--
2.5.0
next prev parent reply other threads:[~2016-03-18 19:26 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-18 19:19 [PATCH 00/30] Stop throwing exceptions from signal handlers Pedro Alves
2016-03-18 19:18 ` [PATCH 18/30] Fix inconsistent handling of EINTR in ser-*.c backends Pedro Alves
2016-03-18 19:18 ` [PATCH 01/30] Don't rely on immediate_quit in command_line_input Pedro Alves
2016-03-18 19:19 ` [PATCH 22/30] Use target_terminal_ours_for_output in infcmd.c Pedro Alves
2016-03-18 19:19 ` [PATCH 29/30] Eliminate immediate_quit Pedro Alves
2016-03-18 19:19 ` [PATCH 02/30] Inline command_loop in read_command_line Pedro Alves
2016-03-18 19:19 ` [PATCH 26/30] Use target_terminal_ours_for_output in MI Pedro Alves
2016-03-18 19:19 ` [PATCH 30/30] Eliminate target_check_pending_interrupt Pedro Alves
2016-03-18 19:19 ` [PATCH 27/30] TUI: GC tui_target_has_run Pedro Alves
2016-03-18 19:19 ` [PATCH 20/30] Use target_terminal_ours_for_output in cp-support.c Pedro Alves
2016-03-18 19:19 ` [PATCH 28/30] target remote: Don't rely on immediate_quit (introduce quit handlers) Pedro Alves
2016-03-18 19:19 ` [PATCH 03/30] TUI: check whether in secondary prompt instead of immediate_quit Pedro Alves
2016-03-18 19:19 ` [PATCH 14/30] Don't call clear_quit_flag in captured_main Pedro Alves
2016-03-18 19:19 ` [PATCH 19/30] ada-lang.c: Introduce type_as_string and use it Pedro Alves
2016-03-18 19:24 ` [PATCH 17/30] Pass Ctrl-C to the target in target_terminal_inferior Pedro Alves
2016-03-18 19:24 ` [PATCH 25/30] Do target_terminal_ours in query & friends instead of in all callers Pedro Alves
2016-03-18 19:24 ` [PATCH 23/30] Use target_terminal_ours_for_output in warning/internal_error Pedro Alves
2016-03-18 19:25 ` [PATCH 08/30] Fix signal handler/event-loop races Pedro Alves
2016-03-18 19:25 ` [PATCH 12/30] Don't call clear_quit_flag in command_handler Pedro Alves
2016-03-18 19:25 ` [PATCH 13/30] Don't call clear_quit_flag in prepare_to_throw_exception Pedro Alves
2016-03-18 19:25 ` [PATCH 04/30] Don't set immediate_quit in prompt_for_continue Pedro Alves
2016-03-18 19:26 ` [PATCH 07/30] Introduce a serial interface for select'able events Pedro Alves
2016-03-18 19:26 ` [PATCH 10/30] Make Python use a struct serial event Pedro Alves
2016-03-18 19:26 ` Pedro Alves [this message]
2016-03-18 19:27 ` [PATCH 21/30] Use target_terminal_ours_for_output in exceptions.c Pedro Alves
2016-03-18 19:27 ` [PATCH 06/30] Remove unused struct serial::name field Pedro Alves
2016-03-18 19:27 ` [PATCH 15/30] Eliminate clear_quit_flag Pedro Alves
2016-03-18 19:28 ` [PATCH 05/30] Stop remote-fileio.c from throwing from SIGINT handler Pedro Alves
2016-03-18 19:28 ` [PATCH 11/30] Don't call clear_quit_flag after check_quit_flag Pedro Alves
2016-03-18 19:37 ` [PATCH 09/30] Introduce interruptible_select Pedro Alves
2016-03-21 17:59 ` Simon Marchi
2016-03-21 18:33 ` Pedro Alves
2016-03-21 19:48 ` Simon Marchi
2016-03-21 19:49 ` Pedro Alves
2016-03-18 19:37 ` [PATCH 16/30] Decouple target_interrupt from all-stop/non-stop modes Pedro Alves
2016-03-21 18:21 ` Simon Marchi
2016-03-21 18:24 ` Pedro Alves
2016-03-21 19:52 ` [PATCH 00/30] Stop throwing exceptions from signal handlers Simon Marchi
2016-03-31 14:43 ` Pedro Alves
2016-03-31 18:44 ` Pedro Alves
2016-04-12 16:15 ` Pedro Alves
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=1458328714-4938-25-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/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