Re: [PATCH OBVIOUS]Fix memory leak in tree-predcom.c

2017-11-03 Thread Richard Biener
On Fri, Nov 3, 2017 at 1:36 PM, Bin Cheng  wrote:
> Hi,
> I ran into this memory leak issue in tree-predcom.c when investigating other 
> PRs.
> This is the obvious fix by freeing reference of trivial component.
> Bootstrap and test on x86_64.  Is it OK?

Ok.

Thanks,
Richard.

> Thanks,
> bin
> 2017-11-02  Bin Cheng  
>
> * tree-predcom.c (determine_roots_comp): Avoid memory leak by freeing
> reference of trivial component.


[PATCH OBVIOUS]Fix memory leak in tree-predcom.c

2017-11-03 Thread Bin Cheng
Hi,
I ran into this memory leak issue in tree-predcom.c when investigating other 
PRs.
This is the obvious fix by freeing reference of trivial component.
Bootstrap and test on x86_64.  Is it OK?

Thanks,
bin
2017-11-02  Bin Cheng  

* tree-predcom.c (determine_roots_comp): Avoid memory leak by freeing
reference of trivial component.diff --git a/gcc/tree-predcom.c b/gcc/tree-predcom.c
index a243bce..e493dcd 100644
--- a/gcc/tree-predcom.c
+++ b/gcc/tree-predcom.c
@@ -1341,7 +1341,14 @@ determine_roots_comp (struct loop *loop,
 
   /* Trivial component.  */
   if (comp->refs.length () <= 1)
-return;
+{
+  if (comp->refs.length () == 1)
+   {
+ free (comp->refs[0]);
+ comp->refs.truncate (0);
+   }
+  return;
+}
 
   comp->refs.qsort (order_drefs);
   FOR_EACH_VEC_ELT (comp->refs, i, a)