clean memory in case of an error