From patchwork Wed May 1 17:37:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 32475 Received: (qmail 35376 invoked by alias); 1 May 2019 17:37:48 -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 35368 invoked by uid 89); 1 May 2019 17:37:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.0 required=5.0 tests=AWL, 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.1 spammy=1051, UD:siginfo-thread.exp, from_tty, sk:siginfo X-HELO: mailsec109.isp.belgacom.be Received: from mailsec109.isp.belgacom.be (HELO mailsec109.isp.belgacom.be) (195.238.20.105) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 May 2019 17:37:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1556732265; x=1588268265; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=w5EHlQmzQdbQ172dWjLgVwgKNFU8kJLpJrWLCgsDsww=; b=DGi2F0uveHob4mEaUmXNZt2QENAf6kXOehddNsEYxLIBn60/emJhvbBa uSMPo4H1OMcS0dz5zww2Bc3w1Re/Vg==; Received: from 59.151-129-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.129.151.59]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 01 May 2019 19:37:43 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leaks by clearing registers and frame caches. Date: Wed, 1 May 2019 19:37:38 +0200 Message-Id: <20190501173738.18155-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Valgrind reports leaks such as the below in the tests: gdb.threads/corethreads.exp gdb.threads/gcore-thread.exp gdb.ada/task_switch_in_core.exp gdb.trace/tfile.exp gdb.base/siginfo-thread.exp ==12701== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,928 of 3,247 ==12701== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344) ==12701== by 0x5CF771: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330) ==12701== by 0x5CF92A: get_thread_regcache (regcache.c:366) ==12701== by 0x5CF92A: get_current_regcache() (regcache.c:372) ==12701== by 0x4C7964: get_current_frame() (frame.c:1587) ==12701== by 0x4C7A3C: get_selected_frame(char const*) (frame.c:1651) ==12701== by 0x669EAD: print_thread_info_1(ui_out*, char const*, int, int, int) (thread.c:1151) ==12701== by 0x66A9A1: info_threads_command(char const*, int) (thread.c:1217) ==12701== by 0x40A878: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892) ... Fix these leaks by clearing registers and frame caches. This leak and fix is similar to the leak fixed by 799efbe8e01 --- gdb/ChangeLog | 5 +++++ gdb/corelow.c | 2 ++ gdb/inferior.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index eba0426463..ce18121a13 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -6229,3 +6229,8 @@ version-control: never coding: utf-8 End: +2019-04-01 Philippe Waroquiers + + * corelow.c (core_target::detach): Ensure frame cache and + register caches are cleared. + inferior.c (exit_inferior_1): Likewise. diff --git a/gdb/corelow.c b/gdb/corelow.c index 3ce612d31b..9fcc2d2372 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -535,6 +535,8 @@ core_target::detach (inferior *inf, int from_tty) 'this'. */ unpush_target (this); + /* Clear the register cache and the frame cache. */ + registers_changed (); reinit_frame_cache (); maybe_say_no_core_file_now (from_tty); } diff --git a/gdb/inferior.c b/gdb/inferior.c index e7b49376e9..abfef700c3 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -208,6 +208,10 @@ exit_inferior_1 (struct inferior *inftoex, int silent) inf->pending_detach = 0; /* Reset it. */ inf->control = inferior_control_state (NO_STOP_QUIETLY); + + /* Clear the register cache and the frame cache. */ + registers_changed (); + reinit_frame_cache (); } void