Fix newly introduced memory leak in
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 Dec 2015 09:38:53 +0000 (09:38 +0000)
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 Dec 2015 09:38:53 +0000 (09:38 +0000)
* hash-traits.h (struct typed_delete_remove): New function.
(typed_delete_remove ::remove): Likewise.
* tree-ssa-loop-ivopts.c (struct iv_common_cand): Replace
auto_vec with vec.
(record_common_cand): Replace XNEW with operator new.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231448 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/hash-traits.h
gcc/tree-ssa-loop-ivopts.c

index bac6627..aff215e 100644 (file)
@@ -1,5 +1,13 @@
 2015-12-09  Martin Liska  <mliska@suse.cz>
 
+       * hash-traits.h (struct typed_delete_remove): New function.
+       (typed_delete_remove ::remove): Likewise.
+       * tree-ssa-loop-ivopts.c (struct iv_common_cand): Replace
+       auto_vec with vec.
+       (record_common_cand): Replace XNEW with operator new.
+
+2015-12-09  Martin Liska  <mliska@suse.cz>
+
        * tree-if-conv.c (ifcvt_local_dce): Replace vec with auto_vec.
 
 2015-12-09  Martin Liska  <mliska@suse.cz>
index 450354a..3997ede 100644 (file)
@@ -38,6 +38,23 @@ typed_free_remove <Type>::remove (Type *p)
   free (p);
 }
 
+/* Helpful type for removing with delete.  */
+
+template <typename Type>
+struct typed_delete_remove
+{
+  static inline void remove (Type *p);
+};
+
+
+/* Remove with delete.  */
+
+template <typename Type>
+inline void
+typed_delete_remove <Type>::remove (Type *p)
+{
+  delete p;
+}
 
 /* Helpful type for a no-op remove.  */
 
@@ -260,6 +277,12 @@ struct nofree_ptr_hash : pointer_hash <T>, typed_noop_remove <T *> {};
 template <typename T>
 struct free_ptr_hash : pointer_hash <T>, typed_free_remove <T> {};
 
+/* Traits for pointer elements that should be freed via delete operand when an
+   element is deleted.  */
+
+template <typename T>
+struct delete_ptr_hash : pointer_hash <T>, typed_delete_remove <T> {};
+
 /* Traits for elements that point to gc memory.  The pointed-to data
    must be kept across collections.  */
 
index 98dc451..d7a0e9e 100644 (file)
@@ -253,13 +253,13 @@ struct iv_common_cand
   tree base;
   tree step;
   /* IV uses from which this common candidate is derived.  */
-  vec<iv_use *> uses;
+  auto_vec<iv_use *> uses;
   hashval_t hash;
 };
 
 /* Hashtable helpers.  */
 
-struct iv_common_cand_hasher : free_ptr_hash <iv_common_cand>
+struct iv_common_cand_hasher : delete_ptr_hash <iv_common_cand>
 {
   static inline hashval_t hash (const iv_common_cand *);
   static inline bool equal (const iv_common_cand *, const iv_common_cand *);
@@ -3127,7 +3127,7 @@ record_common_cand (struct ivopts_data *data, tree base,
   slot = data->iv_common_cand_tab->find_slot (&ent, INSERT);
   if (*slot == NULL)
     {
-      *slot = XNEW (struct iv_common_cand);
+      *slot = new iv_common_cand ();
       (*slot)->base = base;
       (*slot)->step = step;
       (*slot)->uses.create (8);