From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57173 invoked by alias); 18 Mar 2016 19:26:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 57094 invoked by uid 89); 18 Mar 2016 19:26:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Forget, respond X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Mar 2016 19:26:30 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 5D93CC00124A for ; Fri, 18 Mar 2016 19:18:55 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IJIYkM028091 for ; Fri, 18 Mar 2016 15:18:54 -0400 From: Pedro Alves 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 Message-Id: <1458328714-4938-25-git-send-email-palves@redhat.com> In-Reply-To: <1458328714-4938-1-git-send-email-palves@redhat.com> References: <1458328714-4938-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-03/txt/msg00367.txt.bz2 Some of the error paths in these functions leak. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * 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; } @@ -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