From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75735 invoked by alias); 29 Nov 2018 23:05:30 -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 75716 invoked by uid 89); 29 Nov 2018 23:05:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mailsec104.isp.belgacom.be Received: from mailsec104.isp.belgacom.be (HELO mailsec104.isp.belgacom.be) (195.238.20.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Nov 2018 23:05:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1543532726; x=1575068726; h=message-id:subject:from:to:date:in-reply-to:references: mime-version:content-transfer-encoding; bh=9NVlrlEJNUi9bhewXko0ZvGDhl34IzT0wd4Z407bvq8=; b=Mq/bZJXE70QYQD0riFdk5Y36kPOh7ZHiTEYdqYzYKPmELwTQAtpdHbuC YS8fPz80tDCyG6XAW0nY8l77YrlAog==; Received: from 184.205-67-87.adsl-dyn.isp.belgacom.be (HELO md) ([87.67.205.184]) by relay.skynet.be with ESMTP/TLS/AES256-GCM-SHA384; 30 Nov 2018 00:05:24 +0100 Message-ID: <1543532723.4149.7.camel@skynet.be> Subject: Re: [RFA] Fix leak in forward-search From: Philippe Waroquiers To: Pedro Alves , gdb-patches@sourceware.org Date: Thu, 29 Nov 2018 23:05:00 -0000 In-Reply-To: <3cf960b8-ff82-0670-fa90-c94d78573bfe@redhat.com> References: <20181127233328.5164-1-philippe.waroquiers@skynet.be> <3cf960b8-ff82-0670-fa90-c94d78573bfe@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-11/txt/msg00557.txt.bz2 On Thu, 2018-11-29 at 15:42 +0000, Pedro Alves wrote: > On 11/27/2018 11:33 PM, Philippe Waroquiers wrote: > > 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. > > At first sight it would seem like 'buf' was made static to avoid > allocating a growing buffer for each command invocation. > > But then, if that were the case, then you'd want 'cursize' to be > static as well. > > The patch is OK, but I think that replacing 'buf' and all that > manual buffer growing with a non-static gdb::def_vector defined > outside the outer loop would be even better. Thanks for the review, I have pushed this version, but I have added in my todo list the better fix + add a test : I found no explicit functional test for this command + my limited time on GDB development is also shared with analysing the remaining several hundreds tests having a definite leak :). Philippe