fix memory leaks and EngineDump crash