Free resources if we exit with an error.