Correctly release memory for a single shutdown function.