From patchwork Sun Jan 20 18:21:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 31134 Received: (qmail 60926 invoked by alias); 20 Jan 2019 18:21:42 -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 60914 invoked by uid 89); 20 Jan 2019 18:21:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mailsec102.isp.belgacom.be Received: from mailsec102.isp.belgacom.be (HELO mailsec102.isp.belgacom.be) (195.238.20.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 20 Jan 2019 18:21:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1548008491; x=1579544491; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=qbJTaOAcIPH2sJubEGjTNu0pX+jhHIwDaaRHWBrO0uo=; b=Q986RGHGCZCEa/xf7qerbi4SjWdPUFlWkA0j0fp7SKGX1tjzkYQuayna zNauUdxe5EhKN7ttY8gIyxBnp/GP0Q==; Received: from 184.205-67-87.adsl-dyn.isp.belgacom.be (HELO md.home) ([87.67.205.184]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 20 Jan 2019 19:21:28 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak in event-top.c history expansion Date: Sun, 20 Jan 2019 19:21:23 +0100 Message-Id: <20190120182123.2223-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes E.g. in gdb.base/default.exp, valgrind detects leaks such as ==17663== 1,438 bytes in 101 blocks are definitely lost in loss record 2,804 of 2,884 ==17663== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309) ==17663== by 0x418A17: xmalloc (common-utils.c:44) ==17663== by 0x4E6F19C: history_expand (histexpand.c:1061) ==17663== by 0x4B4490: handle_line_of_input(buffer*, char const*, int, char const*) (event-top.c:685) ==17663== by 0x4B4562: command_line_handler(std::unique_ptr >&&) (event-top.c:753) ... Fix the leak by xfree-ing history_value if no expansion took place, as a value is dynamically allocated even if no expansion took place. Tested on debian/amd64, natively and under valgrind. This was tested using the debian system readline library, version 7.0.3 (with upstream patches 002 and 003). gdb/ChangeLog 2019-01-20 Philippe Waroquiers * event-top.c (handle_line_of_input): xfree history_value if no expansion occurred. --- gdb/event-top.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdb/event-top.c b/gdb/event-top.c index 3d3d6275d7..93ea13e3ed 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -705,6 +705,8 @@ handle_line_of_input (struct buffer *cmd_line_buffer, cmd_line_buffer->buffer_size = len + 1; cmd = history_value; } + else + xfree (history_value); } /* If we just got an empty line, and that is supposed to repeat the