Fix bad pointers on exit