memory leak fixes in python interface