“A man died at the time of the Messenger of Allah (ﷺ), and he left no heir except for a slave whom he had set free. The Messenger of Allah (ﷺ) gave the legacy to him.”
Sunan Ibn Majah Book 23, Hadith 23