From: Indu Bhagat <indu.bhagat@oracle.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container ()
Date: Tue, 5 Oct 2021 15:37:30 -0700 [thread overview]
Message-ID: <1633473450-26539-1-git-send-email-indu.bhagat@oracle.com> (raw)
Hello,
This patch fixes an outstanding issue with memory cleanup in the CTF container.
Earlier the two hash tables in the CTF container were not cleaned up in
ctfc_delete_container (). With this patch, we first free up the CTF type and
CTF variable entries in the hash_table slots, followed by emptying of the hash
tables.
Bootstrapped and regression tested on x86_64.
Thanks
------------------------
Free up the memory held by CTF type and CTF variable objects after CTF debug
information has been emitted. In ctfc_delete_container (), traverse the
hash_table of CTF types and CTF variables and free the memory held by the
respective objects.
gcc/ChangeLog:
* ctfc.c (free_ctf_dtdef_cb): New function.
(free_ctf_dvdef_cb): Likewise.
(ctfc_delete_container): Free hash table contents.
---
gcc/ctfc.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/ctfc.c b/gcc/ctfc.c
index 73c118e..1f961c9 100644
--- a/gcc/ctfc.c
+++ b/gcc/ctfc.c
@@ -179,6 +179,26 @@ ctf_dvd_lookup (const ctf_container_ref ctfc, dw_die_ref die)
return NULL;
}
+/* Callback function to free the CTF type from hash table. */
+
+static int
+free_ctf_dtdef_cb (ctf_dtdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
+{
+ if (slot && *slot)
+ ggc_free (*slot);
+ return 1;
+}
+
+/* Callback function to free the CTF variable from hash table. */
+
+static int
+free_ctf_dvdef_cb (ctf_dvdef_ref * slot, void * arg ATTRIBUTE_UNUSED)
+{
+ if (slot && *slot)
+ ggc_free (*slot);
+ return 1;
+}
+
/* Append member definition to the list. Member list is a singly-linked list
with list start pointing to the head. */
@@ -944,11 +964,16 @@ ctfc_delete_strtab (ctf_strtable_t * strtab)
void
ctfc_delete_container (ctf_container_ref ctfc)
{
- /* FIXME - CTF container can be cleaned up now.
- Will the ggc machinery take care of cleaning up the container structure
- including the hash_map members etc. ? */
if (ctfc)
{
+ ctfc->ctfc_types->traverse<void*, free_ctf_dtdef_cb> (NULL);
+ ctfc->ctfc_types->empty ();
+ ctfc->ctfc_types = NULL;
+
+ ctfc->ctfc_vars->traverse<void*, free_ctf_dvdef_cb> (NULL);
+ ctfc->ctfc_vars->empty ();
+ ctfc->ctfc_types = NULL;
+
ctfc_delete_strtab (&ctfc->ctfc_strtable);
ctfc_delete_strtab (&ctfc->ctfc_aux_strtable);
if (ctfc->ctfc_vars_list)
--
1.8.3.1
next reply other threads:[~2021-10-05 22:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 22:37 Indu Bhagat [this message]
2021-10-07 7:58 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1633473450-26539-1-git-send-email-indu.bhagat@oracle.com \
--to=indu.bhagat@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).