From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126654 invoked by alias); 5 Oct 2016 15:44:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 126644 invoked by uid 89); 5 Oct 2016 15:44:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=BAYES_00,MEDICAL_SUBJECT,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=readmdc, read-md.c, streams, reader X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Oct 2016 15:44:35 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB7D51CCA8C for ; Wed, 5 Oct 2016 15:44:34 +0000 (UTC) Received: from c64.redhat.com (vpn-236-9.phx2.redhat.com [10.3.236.9]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u95FiV5J027350; Wed, 5 Oct 2016 11:44:34 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 01/16] read-md.c: Add various cleanups to ~rtx_reader Date: Wed, 05 Oct 2016 15:44:00 -0000 Message-Id: <1475684110-2521-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1475684110-2521-1-git-send-email-dmalcolm@redhat.com> References: <1475684110-2521-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00258.txt.bz2 Various global data items relating to reading .md files are currently initialized in rtx_reader::read_md_files, and are not cleaned up. The selftests for the RTL frontend require supporting multiple reader instances being alive one after another in-process, so this lack of cleanup would become a leak. To fix this, this patch moves these initializations to the rtx_reader constructor, and adds matching cleanups to the destructor, along with a cleanup of m_base_dir. gcc/ChangeLog: * read-md.c (rtx_reader::rtx_reader): Move initializations of various global data from rtx_reader::read_md_files to here. (rtx_reader::~rtx_reader): Clean up m_base_dir, and various global data. (rtx_reader::read_md_files): Move initializations of various global data from here to the ctor. --- gcc/read-md.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/gcc/read-md.c b/gcc/read-md.c index e158be5..1a13916 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -925,12 +925,47 @@ rtx_reader::rtx_reader () { /* Set the global singleton pointer. */ rtx_reader_ptr = this; + + /* Initialize global data. */ + obstack_init (&string_obstack); + ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); + obstack_init (&ptr_loc_obstack); + joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); + obstack_init (&joined_conditions_obstack); + md_constants = htab_create (31, leading_string_hash, + leading_string_eq_p, (htab_del) 0); + enum_types = htab_create (31, leading_string_hash, + leading_string_eq_p, (htab_del) 0); + + /* Unlock the stdio streams. */ + unlock_std_streams (); } /* rtx_reader's destructor. */ rtx_reader::~rtx_reader () { + free (m_base_dir); + + /* Clean up global data. */ + htab_delete (enum_types); + enum_types = NULL; + + htab_delete (md_constants); + md_constants = NULL; + + obstack_free (&joined_conditions_obstack, NULL); + + htab_delete (joined_conditions); + joined_conditions = NULL; + + obstack_free (&ptr_loc_obstack, NULL); + + htab_delete (ptr_locs); + ptr_locs = NULL; + + obstack_free (&string_obstack, NULL); + /* Clear the global singleton pointer. */ rtx_reader_ptr = NULL; } @@ -1105,20 +1140,6 @@ rtx_reader::read_md_files (int argc, const char **argv, bool already_read_stdin; int num_files; - /* Initialize global data. */ - obstack_init (&string_obstack); - ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); - obstack_init (&ptr_loc_obstack); - joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); - obstack_init (&joined_conditions_obstack); - md_constants = htab_create (31, leading_string_hash, - leading_string_eq_p, (htab_del) 0); - enum_types = htab_create (31, leading_string_hash, - leading_string_eq_p, (htab_del) 0); - - /* Unlock the stdio streams. */ - unlock_std_streams (); - /* First we loop over all the options. */ for (i = 1; i < argc; i++) if (argv[i][0] == '-') -- 1.8.5.3