fix memory leaks in previous commit