From: Martin Liska Date: Wed, 9 Dec 2015 09:38:53 +0000 (+0100) Subject: Fix newly introduced memory leak in X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=74fbae9278d935f5623498edc2235fcbba4f9578;p=gcc.git Fix newly introduced memory leak in * 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. From-SVN: r231448 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bac6627f24f..aff215e889d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-12-09 Martin Liska + + * 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 * tree-if-conv.c (ifcvt_local_dce): Replace vec with auto_vec. diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h index 450354ae1d7..3997eded127 100644 --- a/gcc/hash-traits.h +++ b/gcc/hash-traits.h @@ -38,6 +38,23 @@ typed_free_remove ::remove (Type *p) free (p); } +/* Helpful type for removing with delete. */ + +template +struct typed_delete_remove +{ + static inline void remove (Type *p); +}; + + +/* Remove with delete. */ + +template +inline void +typed_delete_remove ::remove (Type *p) +{ + delete p; +} /* Helpful type for a no-op remove. */ @@ -260,6 +277,12 @@ struct nofree_ptr_hash : pointer_hash , typed_noop_remove {}; template struct free_ptr_hash : pointer_hash , typed_free_remove {}; +/* Traits for pointer elements that should be freed via delete operand when an + element is deleted. */ + +template +struct delete_ptr_hash : pointer_hash , typed_delete_remove {}; + /* Traits for elements that point to gc memory. The pointed-to data must be kept across collections. */ diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 98dc4518fa3..d7a0e9eaf0c 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -253,13 +253,13 @@ struct iv_common_cand tree base; tree step; /* IV uses from which this common candidate is derived. */ - vec uses; + auto_vec uses; hashval_t hash; }; /* Hashtable helpers. */ -struct iv_common_cand_hasher : free_ptr_hash +struct iv_common_cand_hasher : delete_ptr_hash { 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);