fix memory leaks

fix #140