fix memory leak in python interface