From patchwork Sun Feb 17 19:50:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 31493 Received: (qmail 3232 invoked by alias); 17 Feb 2019 19:50:51 -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 3214 invoked by uid 89); 17 Feb 2019 19:50:50 -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=Key, 29516, 762, our 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; Sun, 17 Feb 2019 19:50:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1550433048; x=1581969048; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/HcAuNTukJeXyx0KmkY68knZLBhNn5YorLQfqFlnKBk=; b=z4v6JICaNOm0JqzegYyZW/faqnTC7td5/l+xsB54XBDXOqXKfda8GjyM Zs4uJWoBFeMZ9Y0zm/bZe0CRWt8PiQ==; Received: from 147.122-130-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.130.122.147]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 17 Feb 2019 20:50:44 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix leaks of 'per program space' and 'per inferior' ada task data. Date: Sun, 17 Feb 2019 20:50:37 +0100 Message-Id: <20190217195037.25482-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes Valgrind reports leaks such as the below. Fix these leaks by changing ada_tasks_pspace_data_handle and ada_tasks_inferior_data_handle to use the 'with_cleanup' register variant. Tested on debian/amd64 natively and under Valgrind. ==26346== 56 bytes in 1 blocks are definitely lost in loss record 631 of 3,249 ==26346== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344) ==26346== by 0x38F911: get_ada_tasks_inferior_data(inferior*) (ada-tasks.c:281) ==26346== by 0x38FA3F: ada_tasks_invalidate_inferior_data (ada-tasks.c:1362) ==26346== by 0x38FA3F: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1411) ==26346== by 0x60CBC5: operator() (functional:2127) ==26346== by 0x60CBC5: notify (observable.h:106) ==26346== by 0x60CBC5: clear_symtab_users(enum_flags) (symfile.c:2903) ... ==26346== 104 bytes in 1 blocks are definitely lost in loss record 984 of 3,249 ==26346== at 0x4C2E0BC: calloc (vg_replace_malloc.c:762) ==26346== by 0x4056F0: xcalloc (common-utils.c:84) ==26346== by 0x38F8AE: xcnew (poison.h:122) ==26346== by 0x38F8AE: get_ada_tasks_pspace_data(program_space*) (ada-tasks.c:253) ==26346== by 0x38FA77: ada_tasks_invalidate_pspace_data (ada-tasks.c:1354) ==26346== by 0x38FA77: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1394) ==26346== by 0x60CBC5: operator() (functional:2127) ==26346== by 0x60CBC5: notify (observable.h:106) ... gdb/ChangeLog 2019-02-17 Philippe Waroquiers * ada-task.c (_initialize_tasks): Use 'with_cleanup' register variant for ada_tasks_pspace_data_handle and ada_tasks_inferior_data_handle. (ada_tasks_pspace_data_cleanup): New function. (ada_tasks_inferior_data_cleanup): New function. --- gdb/ada-tasks.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index e994147a66..151fae3abb 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -161,6 +161,16 @@ struct ada_tasks_pspace_data /* Key to our per-program-space data. */ static const struct program_space_data *ada_tasks_pspace_data_handle; +/* A cleanup routine for our per-program-space data. */ +static void +ada_tasks_pspace_data_cleanup (struct program_space *pspace, void *arg) +{ + struct ada_tasks_pspace_data *data + = (struct ada_tasks_pspace_data *) arg; + if (data != NULL) + XDELETE (data); +} + /* The kind of data structure used by the runtime to store the list of Ada tasks. */ @@ -285,6 +295,16 @@ get_ada_tasks_inferior_data (struct inferior *inf) return data; } +/* A cleanup routine for our per-inferior data. */ +static void +ada_tasks_inferior_data_cleanup (struct inferior *inf, void *arg) +{ + struct ada_tasks_inferior_data *data + = (struct ada_tasks_inferior_data *) arg; + if (data != NULL) + delete data; +} + /* Return the task number of the task whose thread is THREAD, or zero if the task could not be found. */ @@ -1414,8 +1434,12 @@ ada_tasks_new_objfile_observer (struct objfile *objfile) void _initialize_tasks (void) { - ada_tasks_pspace_data_handle = register_program_space_data (); - ada_tasks_inferior_data_handle = register_inferior_data (); + ada_tasks_pspace_data_handle + = register_program_space_data_with_cleanup (NULL, + ada_tasks_pspace_data_cleanup); + ada_tasks_inferior_data_handle + = register_inferior_data_with_cleanup (NULL, + ada_tasks_inferior_data_cleanup); /* Attach various observers. */ gdb::observers::normal_stop.attach (ada_tasks_normal_stop_observer);