Memory leak in polyhedral_reuse_analysis.c due to node to constant to int conversion
In polyhedral_reuse_analysis.c
, the pattern COconst2Int (COaST2Constant (node))
occurs 13 times, leaking the constant every single time.
The code guards the conversion as in a way similar to this:
if (COisConstant (some_node)
&& COisConstant (more_nodes)) {
some_int = COconst2Int (COaST2Constant (some_node);
more_ints = COconst2Int (COaST2Constant (more_ints));
// code using the integers here
}
This format is also what I need for an optimization I'm writing.
Should we add this function to constants_basic.c
?
int
COaST2IntUnchecked (node *a) {
constant *tmp_const;
int res;
DBUG_ENTER ();
tmp_const = COaST2Constant (a);
DBUG_ASSERT (tmp_const != NULL,
"COaST2IntUnchecked was used without checking"
" whether the node is indeed a constant.");
res = COconst2Int (tmp_const);
COfreeConstant (tmp_const);
DBUG_RETURN (res);
}
It would allow the code in polyhedral_reuse_analysis.c
to be refactorable with simply a find + replace, fixing the memory leak, as well as making the code for my optimization a lot simpler.