From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id B15A03858C39 for ; Thu, 7 Oct 2021 07:58:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B15A03858C39 Received: by mail-ed1-x52d.google.com with SMTP id d8so19719755edx.9 for ; Thu, 07 Oct 2021 00:58:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+ztV8PRHdzvjYoxabSVaMwrf4kEbqLncOjCTu58mCO4=; b=WV0GdwxG17J0pIUPFjPKltgOi/YsZv+MHvlN37+1+gSKuMZuJ7aJYKPlkkvdUKKclH rkj9P93wT9WGeWahrzWWkffL4yDzBU5eIpvOL/yFiXdJnJySr4rVezBTg3UhYej6DCrZ bOMzoot/Z2ut/3aGyYeWhP4DbrY6Cu1Na/jh42apfirceRg9f/gkfqufVLp/N3b4Tgcz lahhXxWL6/Kf1TG56eJyHdscYTdXoNzWC+y5mlxIKgwlewe/GAOA0zYW/JhH4Cp+9Jov YshMSWz5eCYiudjJOBNENN0IhPm/U9isIkq00g5XrXyR926PWAKw0ee8F2WPmJajxyzS tW8A== X-Gm-Message-State: AOAM532vzgXnyvdfLNqofAEwO/ty5+bPBQz7miZiKSNosoi5d7pMcN/Z Pjc7sQaZ4ezGKKC2fnLMYKwksYeGVu/qt35PtqM= X-Google-Smtp-Source: ABdhPJyA7wyOa/GzX1aVJn1hBJyOlGB6CY9Zw6uhSHVqP45unMjF21h1sp308h91odDAMLL6+4Y1IsguYYTlaV6PXMI= X-Received: by 2002:a50:e0c3:: with SMTP id j3mr4272182edl.97.1633593520798; Thu, 07 Oct 2021 00:58:40 -0700 (PDT) MIME-Version: 1.0 References: <1633473450-26539-1-git-send-email-indu.bhagat@oracle.com> In-Reply-To: <1633473450-26539-1-git-send-email-indu.bhagat@oracle.com> From: Richard Biener Date: Thu, 7 Oct 2021 09:58:29 +0200 Message-ID: Subject: Re: [PATCH] ctfc: Free CTF type and CTF variable objects in ctfc_delete_container () To: Indu Bhagat Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 07:58:43 -0000 On Wed, Oct 6, 2021 at 12:38 AM Indu Bhagat via Gcc-patches 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 (NULL); > + ctfc->ctfc_types->empty (); > + ctfc->ctfc_types = NULL; > + > + ctfc->ctfc_vars->traverse (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 >