From patchwork Tue Nov 27 23:33:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30339 Received: (qmail 124609 invoked by alias); 27 Nov 2018 23:34:02 -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 124544 invoked by uid 89); 27 Nov 2018 23:34:02 -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 autolearn=ham version=3.3.2 spammy=3149, HContent-Transfer-Encoding:8bit X-HELO: mailsec113.isp.belgacom.be Received: from mailsec113.isp.belgacom.be (HELO mailsec113.isp.belgacom.be) (195.238.20.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Nov 2018 23:34:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1543361641; x=1574897641; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FRWgNT/dpnmP7N+N1yI46Qe4foVjmxhrMxEFt4tdgQQ=; b=YD0mvVTZkz2P4/6/MeQCp+zAuPyoM4gkxevjOnfWDDjBXGXtFI/cz27w 4v8WoLbLSKuN7rRSofg8RkvNLqgQyA==; 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; 28 Nov 2018 00:33:59 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak in forward-search Date: Wed, 28 Nov 2018 00:33:28 +0100 Message-Id: <20181127233328.5164-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Valgrind reports the below leak. Fix the leak by using xrealloc, even for the first allocation, as buf is static. ==29158== 5,888 bytes in 23 blocks are definitely lost in loss record 3,028 of 3,149 ==29158== at 0x4C2BE2D: malloc (vg_replace_malloc.c:299) ==29158== by 0x41B557: xmalloc (common-utils.c:44) ==29158== by 0x60B7D9: forward_search_command(char const*, int) (source.c:1563) ==29158== by 0x40BA68: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1888) ==29158== by 0x665300: execute_command(char const*, int) (top.c:630) ... gdb/ChangeLog 2018-11-28 Philippe Waroquiers * source.c (forward_search_command): Fix leak by using xrealloc even for the first allocation in the loop, as buf is static. --- gdb/source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/source.c b/gdb/source.c index e295fbf49e..c75351e65f 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1560,7 +1560,7 @@ forward_search_command (const char *regex, int from_tty) int cursize, newsize; cursize = 256; - buf = (char *) xmalloc (cursize); + buf = (char *) xrealloc (buf, cursize); p = buf; c = fgetc (stream.get ());