The strlen pass initializes its pointer_query member object with
a cache consisting of a couple of vec's.  Because vec doesn't
implement RAII its memory must be explicitly released to avoid
memory leaks.  The attached patch adds a dtor to
the strlen_dom_walker to do that.

Tested on x86_64-linux and by verifying that the cache leaks are
gone by compiling gcc.dg/Wstringop-overflow*.c tests under Valgrind.

I'll plan to commit this change as "obvious" tomorrow unless there
are suggestions for changes.

Martin

PS Valgrind shows a fair number of leaks even with the patch but
none of them due to the pointer_query cache.
PR tree-optimization/98937 - pointer_query cache leaks

gcc/ChangeLog:

	PR tree-optimization/98937
	* tree-ssa-strlen.c (strlen_dom_walker::~strlen_dom_walker): Define.
	Flush pointer_query cache.

diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index c6f74051607..8912a113de9 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -5491,6 +5491,8 @@ public:
     m_cleanup_cfg (false)
   { }
 
+  ~strlen_dom_walker ();
+
   virtual edge before_dom_children (basic_block);
   virtual void after_dom_children (basic_block);
 
@@ -5508,6 +5510,13 @@ public:
   bool m_cleanup_cfg;
 };
 
+/* Release pointer_query cache.  */
+
+strlen_dom_walker::~strlen_dom_walker ()
+{
+  ptr_qry.flush_cache ();
+}
+
 /* Callback for walk_dominator_tree.  Attempt to optimize various
    string ops by remembering string lengths pointed by pointer SSA_NAMEs.  */
 

Reply via email to