fix memory leak for polynomial