autowrap, fix memory leaks