It is narrated from Sayyiduna Abu Umamah (may Allah be pleased with him) that he said: I heard the Messenger of Allah (peace and blessings be upon him) say: "When Allah intends good for a servant, He purifies him before his death." The Companions said: O Messenger of Allah! What is the purification of the servant? He said: "A righteous deed which he is enabled to do, until his soul is taken upon it."
Hadith Referenceالمعجم الكبير للطبراني / باب الصاد / 7869