fix memory leak when 'pt' is not null