From 7f153d8202c35578ca22746d2c3297f4a83272fb Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 19 May 2016 17:06:17 +0200 Subject: [PATCH] Fix memory leak in ipa-pure-const * ipa-pure-const.c (set_function_state): Remove an existing funct_state. (remove_node_data): Do not free it as it's released in set_function_state. From-SVN: r236469 --- gcc/ChangeLog | 7 +++++++ gcc/ipa-pure-const.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ab513e6cac4..effe9c31a7f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-05-19 Martin Liska + + * ipa-pure-const.c (set_function_state): Remove an existing + funct_state. + (remove_node_data): Do not free it as it's released + in set_function_state. + 2016-05-19 Martin Liska * tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Release diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index ba76275a696..a9570e4aa6c 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -258,6 +258,13 @@ set_function_state (struct cgraph_node *node, funct_state s) if (!funct_state_vec.exists () || funct_state_vec.length () <= (unsigned int)node->uid) funct_state_vec.safe_grow_cleared (node->uid + 1); + + /* If funct_state_vec already contains a funct_state, we have to release + it before it's going to be ovewritten. */ + if (funct_state_vec[node->uid] != NULL + && funct_state_vec[node->uid] != &varying_state) + free (funct_state_vec[node->uid]); + funct_state_vec[node->uid] = s; } @@ -956,12 +963,7 @@ static void remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) { if (has_function_state (node)) - { - funct_state l = get_function_state (node); - if (l != &varying_state) - free (l); - set_function_state (node, NULL); - } + set_function_state (node, NULL); } -- 2.30.2