Fix memory leak in PTA

Message ID 20230223132126.96E7E139B5@imap2.suse-dmz.suse.de
State Repeat Merge
Headers
Series Fix memory leak in PTA |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Richard Biener Feb. 23, 2023, 1:21 p.m. UTC
  When handle_lhs_call calls .create on the passed in vector it leaks
any previous allocated storage.  Avoid doing that and instead rely
on the caller for memory management, just truncate the vector.

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

	* tree-ssa-structalias.cc (handle_lhs_call): Do not
	re-create rhsc, only truncate it.
---
 gcc/tree-ssa-structalias.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 2ed32de06ed..07e0fd6827a 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -4408,17 +4408,17 @@  handle_lhs_call (gcall *stmt, tree lhs, int flags, vec<ce_s> &rhsc,
       && (flags & ERF_RETURN_ARG_MASK) < gimple_call_num_args (stmt))
     {
       tree arg;
-      rhsc.create (0);
+      rhsc.truncate (0);
       arg = gimple_call_arg (stmt, flags & ERF_RETURN_ARG_MASK);
       get_constraint_for (arg, &rhsc);
       process_all_all_constraints (lhsc, rhsc);
-      rhsc.release ();
+      rhsc.truncate (0);
     }
   else if (flags & ERF_NOALIAS)
     {
       varinfo_t vi;
       struct constraint_expr tmpc;
-      rhsc.create (0);
+      rhsc.truncate (0);
       vi = make_heapvar ("HEAP", true);
       /* We are marking allocated storage local, we deal with it becoming
          global by escaping and setting of vars_contains_escaped_heap.  */
@@ -4435,7 +4435,7 @@  handle_lhs_call (gcall *stmt, tree lhs, int flags, vec<ce_s> &rhsc,
       tmpc.type = ADDRESSOF;
       rhsc.safe_push (tmpc);
       process_all_all_constraints (lhsc, rhsc);
-      rhsc.release ();
+      rhsc.truncate (0);
     }
   else
     process_all_all_constraints (lhsc, rhsc);