On Wed, Oct 6, 2021 at 12:38 AM Indu Bhagat via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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;
> +

it should be enough to set ctfc_types to NULL, in particular traversing
the table shouldn't be needed.

OK with that change.

Thanks,
Richard.

>        ctfc_delete_strtab (&ctfc->ctfc_strtable);
>        ctfc_delete_strtab (&ctfc->ctfc_aux_strtable);
>        if (ctfc->ctfc_vars_list)
> --
> 1.8.3.1
>

Reply via email to