Free dynamically allocated memory on exit