From patchwork Wed Jul 8 20:37:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 7594 Received: (qmail 62504 invoked by alias); 8 Jul 2015 20:37:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 61035 invoked by uid 89); 8 Jul 2015 20:37:49 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail-wi0-f181.google.com Received: from mail-wi0-f181.google.com (HELO mail-wi0-f181.google.com) (209.85.212.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 08 Jul 2015 20:37:48 +0000 Received: by wiclp1 with SMTP id lp1so91470685wic.0 for ; Wed, 08 Jul 2015 13:37:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WScnGZk/nJq5pzDKz/2BG1Ofm/EMgIAfzjcLAirLj5Y=; b=SuKeg3OebiLv75B387wjSUlb8rn25fLf5Z1T4w9QSIUJndkCJQkNMtJBnP8i09TPkF yOiA8NkUXb31ZJxkrvIwLBBMvPPIGmEI7kVTbvplNZqPSwXIPfcAGP/H7E802AUdA37o LGhVlfewpOi7LMETMPS4d5J3pk+mXC8Rq2BK93GFMz4mxDGSanx45qfhbb9CizeH77iA y0al/K3YUyCdkOhkgu8qHTSpqDNwKkIuzRhr+4TOvmYK4lWQ3vdaWgNScDTGiOFNnKWf DFseBuR79ajgDX/ad15OjSQV9wlxEsAfY3+hDBhalZfSgEnrYaOQpXCsAsUY6oHTfWpp 9VNQ== X-Gm-Message-State: ALoCoQn0cVU2FL8LFfnoFBzN8cSG4q/sy5hCJX48nES3wtYaw0raSf/BtJVj80LxBTb2nG0oFnPO X-Received: by 10.180.102.74 with SMTP id fm10mr117283784wib.25.1436387865766; Wed, 08 Jul 2015 13:37:45 -0700 (PDT) Received: from localhost (host81-158-4-174.range81-158.btcentralplus.com. [81.158.4.174]) by smtp.gmail.com with ESMTPSA id sc16sm5206837wjb.28.2015.07.08.13.37.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2015 13:37:45 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb/tui: Use cleanups to free string copies. Date: Wed, 8 Jul 2015 21:37:30 +0100 Message-Id: <2bc5aca25e4fbde8ac236496c715c67bf8eec3c0.1436387456.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes In parse_scrolling_args it is possible for a string copy to leak if an error occurs. Switching to using a cleanup fixes this leak. In tui_set_win_height the string can't be leaked, but switching to using a cleanup guards against the possibility that a leak could be introduced in the future (by adding an error somewhere in the call stack). gdb/ChangeLog: * tui/tui-win.c (tui_set_win_height): Use a cleanup to free the string copy. (parse_scrolling_args): Likewise. --- gdb/ChangeLog | 6 ++++++ gdb/tui/tui-win.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 646bc5b..e995f01 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2015-07-06 Andrew Burgess + * tui/tui-win.c (tui_set_win_height): Use a cleanup to free the + string copy. + (parse_scrolling_args): Likewise. + +2015-07-06 Andrew Burgess + * tui/tui-win.c (focus_completer): Don't duplicate the tui window names in this function. diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 947608a..cdf322b 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -1141,7 +1141,9 @@ tui_set_win_height (char *arg, int from_tty) char *wname = (char *) NULL; int new_height, i; struct tui_win_info *win_info; + struct cleanup *old_chain; + old_chain = make_cleanup (xfree, buf); wname = buf_ptr; buf_ptr = strchr (buf_ptr, ' '); if (buf_ptr != (char *) NULL) @@ -1204,8 +1206,7 @@ The window name specified must be valid and visible.\n")); else printf_filtered (WIN_HEIGHT_USAGE); - if (buf != (char *) NULL) - xfree (buf); + do_cleanups (old_chain); } else printf_filtered (WIN_HEIGHT_USAGE); @@ -1636,9 +1637,11 @@ parse_scrolling_args (char *arg, if (arg != (char *) NULL) { char *buf, *buf_ptr; + struct cleanup *old_chain; /* Process the number of lines to scroll. */ buf = buf_ptr = xstrdup (arg); + old_chain = make_cleanup (xfree, buf); if (isdigit (*buf_ptr)) { char *num_str; @@ -1686,6 +1689,6 @@ The window name specified must be valid and visible.\n")); else if (*win_to_scroll == TUI_CMD_WIN) *win_to_scroll = (tui_source_windows ())->list[0]; } - xfree (buf); + do_cleanups (old_chain); } }