Fix mem leaks (PLY)