public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/113475 - fix memory leak in phi_analyzer
Date: Thu, 18 Jan 2024 13:31:33 +0100 (CET)	[thread overview]
Message-ID: <20240118123133.gbcP6sKRynr7VXZTV0Xm9gaNJoMRSrJrXeeQuBHA3C4@z> (raw)

phi_analyzer leaks all phi_group objects it allocates.  The following
fixes this by maintaining a vector of allocated objects and release
them when destroying the phi_analyzer object.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

	PR tree-optimization/113475
	* gimple-range-phi.h (phi_analyzer::m_phi_groups): New.
	* gimple-range-phi.cc (phi_analyzer::phi_analyzer): Initialize.
	(phi_analyzer::~phi_analyzer): Deallocate and free collected
	phi_grous.
	(phi_analyzer::process_phi): Record allocated phi_groups.
---
 gcc/gimple-range-phi.cc | 6 +++++-
 gcc/gimple-range-phi.h  | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-range-phi.cc b/gcc/gimple-range-phi.cc
index 5aee761c6f4..01900a35b32 100644
--- a/gcc/gimple-range-phi.cc
+++ b/gcc/gimple-range-phi.cc
@@ -254,7 +254,7 @@ phi_group::dump (FILE *f)
 
 // Construct a phi analyzer which uses range_query G to pick up values.
 
-phi_analyzer::phi_analyzer (range_query &g) : m_global (g)
+phi_analyzer::phi_analyzer (range_query &g) : m_global (g), m_phi_groups (vNULL)
 {
   m_work.create (0);
   m_work.safe_grow (20);
@@ -273,6 +273,9 @@ phi_analyzer::~phi_analyzer ()
   bitmap_obstack_release (&m_bitmaps);
   m_tab.release ();
   m_work.release ();
+  for (auto grp : m_phi_groups)
+    delete grp;
+  m_phi_groups.release ();
 }
 
 //  Return the group, if any, that NAME is part of.  Do no analysis.
@@ -458,6 +461,7 @@ phi_analyzer::process_phi (gphi *phi)
 	  if (!cyc.range ().varying_p ())
 	    {
 	      g = new phi_group (cyc);
+	      m_phi_groups.safe_push (g);
 	      if (dump_file && (dump_flags & TDF_DETAILS))
 		{
 		  fprintf (dump_file, "PHI ANALYZER : New ");
diff --git a/gcc/gimple-range-phi.h b/gcc/gimple-range-phi.h
index 04747ba9784..a40aece5b22 100644
--- a/gcc/gimple-range-phi.h
+++ b/gcc/gimple-range-phi.h
@@ -87,6 +87,7 @@ protected:
 
   bitmap m_simple;       // Processed, not part of a group.
   bitmap m_current;	 // Potential group currently being analyzed.
+  vec<phi_group *> m_phi_groups;
   vec<phi_group *> m_tab;
   bitmap_obstack m_bitmaps;
 };
-- 
2.35.3

                 reply	other threads:[~2024-01-18 12:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240118123133.gbcP6sKRynr7VXZTV0Xm9gaNJoMRSrJrXeeQuBHA3C4@z \
    --to=rguenther@suse.de \
    --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).