diff options
author | Pedro Alves <palves@redhat.com> | 2016-04-12 16:49:31 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-04-12 16:59:42 +0100 |
commit | 80dbc9fdc7a7929c16f58852e45196a32877b013 (patch) | |
tree | e064b814913a960bc7a1ee3034cc4af6db39eaaa | |
parent | c5ac15402a894e87a118526a066880f596b3c78d (diff) | |
download | gdb-80dbc9fdc7a7929c16f58852e45196a32877b013.zip gdb-80dbc9fdc7a7929c16f58852e45196a32877b013.tar.gz gdb-80dbc9fdc7a7929c16f58852e45196a32877b013.tar.bz2 |
Add missing cleanups to defaulted_query and prompt_for_continue
Some of the error paths in these functions leak.
gdb/ChangeLog:
2016-04-12 Pedro Alves <palves@redhat.com>
* utils.c (defaulted_query, prompt_for_continue): Free temporary
strings with cleanups, instead of xfree.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/utils.c | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 595a43c..83235c3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-04-12 Pedro Alves <palves@redhat.com> + * utils.c (defaulted_query, prompt_for_continue): Free temporary + strings with cleanups, instead of xfree. + +2016-04-12 Pedro Alves <palves@redhat.com> + * utils.c (vwarning, internal_vproblem): Use make_cleanup_restore_target_terminal and target_terminal_ours_for_output. diff --git a/gdb/utils.c b/gdb/utils.c index e44e76c..760c376 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1241,6 +1241,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') @@ -1295,13 +1296,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); @@ -1352,9 +1356,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; } @@ -1859,6 +1863,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); @@ -1881,6 +1886,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); @@ -1891,7 +1897,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; @@ -1900,7 +1906,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 @@ -1908,6 +1913,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. */ |