From patchwork Tue Jan 1 13:30:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30925 Received: (qmail 62225 invoked by alias); 1 Jan 2019 13:30:31 -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 62163 invoked by uid 89); 1 Jan 2019 13:30:28 -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=leaks, HContent-Transfer-Encoding:8bit X-HELO: mailsec112.isp.belgacom.be Received: from mailsec112.isp.belgacom.be (HELO mailsec112.isp.belgacom.be) (195.238.20.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Jan 2019 13:30:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1546349426; x=1577885426; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=77IqjZ5D3SiH7Gp0zAv/QszJVjdosDGGJdzrqGHEais=; b=U/Xj7L3r2uAgWOtWet8Vx3d4eEL4B6jAtMvYaEnkdttmrD4tTKxSDMLP zaB/8QAdp7hCBbB1s1/PTdYwSSyEYA==; 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; 01 Jan 2019 14:30:22 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leak in record-full.c Date: Tue, 1 Jan 2019 14:30:17 +0100 Message-Id: <20190101133017.13425-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes valgrind detects leaks in several gdb.reverse tests, such as the below in gdb.reverse/watch-precsave.exp. Fix the leak by rewriting the loop that frees record_full_core_buf_list. gdb/ChangeLog 2019-01-01 Philippe Waroquiers * record-full.c (record_full_base_target::close): Rewrite record_full_core_buf_list free logic. ==18847== VALGRIND_GDB_ERROR_BEGIN ==18847== 4,120 (24 direct, 4,096 indirect) bytes in 1 blocks are definitely lost in loss record 3,094 of 3,199 ==18847== at 0x4C2BE6D: malloc (vg_replace_malloc.c:309) ==18847== by 0x405097: xmalloc (common-utils.c:44) ==18847== by 0x5AF8EA: xnew (poison.h:110) ==18847== by 0x5AF8EA: record_full_core_target::xfer_partial(target_object, char const*, unsigned char*, unsigned char const*, unsigned long, unsigned long, unsigned long*) (record-full.c:2182) ==18847== by 0x64677D: raw_memory_xfer_partial(target_ops*, unsigned char*, unsigned char const*, unsigned long, long, unsigned long*) (target.c:956) ==18847== by 0x64691E: memory_xfer_partial_1(target_ops*, target_object, unsigned char*, unsigned char const*, unsigned long, unsigned long, unsigned long*) (target.c:1086) --- gdb/record-full.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gdb/record-full.c b/gdb/record-full.c index 2b918eaabf..8738512f28 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -1014,15 +1014,11 @@ record_full_base_target::close () } /* Release record_full_core_buf_list. */ - if (record_full_core_buf_list) + while (record_full_core_buf_list) { - for (entry = record_full_core_buf_list->prev; entry; - entry = entry->prev) - { - xfree (record_full_core_buf_list); - record_full_core_buf_list = entry; - } - record_full_core_buf_list = NULL; + entry = record_full_core_buf_list; + record_full_core_buf_list = record_full_core_buf_list->prev; + xfree (entry); } if (record_full_async_inferior_event_token)