عَنِ ابْنِ عُمَرَ رَضِيَ اللَّهُ عَنْهُمَا قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «مَنْ أَعْتَقَ شِرْكًا لَهُ فِي عَبْدٍ وَكَانَ لَهُ مَالٌ يَبْلُغُ ثَمَنَ الْعَبْدِ قُوِّمَ الْعَبْدُ قِيمَةَ عَدْلٍ فَأُعْطِيَ شُرَكَاؤُهُ حِصَصَهُمْ وَعَتَقَ عَلَيْهِ الْعَبْدُ وَإِلَّا فَقَدْ عَتَقَ مِنْهُ مَا عَتَقَ»
Translation
Jabir said that a man of the Ansar declared that a slave would be free after his death, but he had no other property, so when the Prophet heard of that he said, “Who will buy him from me ?” and Nu'aim b. an-Nahham bought him for eight hundred dirhams. A version by Muslim says Nu'aim b. ‘Abdallah al-‘Adawi bought him for eight hundred dirhams which he brought to the Prophet who, when he had handed them over to the man, said, “Spend first on yourself giving yourself sadaqa

if anything is left over give it to your family; if anything is left over when they have received something, give it to your relatives; and if anything is left over when they have received something, do thus and thus,” meaning that it should be distributed in front of him, on his right and on his left.(Bukhari and Muslim.)