It is narrated from al-Hasan (may Allah have mercy on him) that the Prophet (peace and blessings be upon him) went out to al-Baqi' and saw a man being sold. He (peace and blessings be upon him) bargained over him, then left him. A man bought him and set him free, then brought him to the Prophet (peace and blessings be upon him) and said: I bought this man and then set him free; what is your view? He (peace and blessings be upon him) said: "He is your brother and your mawla." He asked: What is your view about keeping company with him? He (peace and blessings be upon him) said: "If he is grateful to you, it is better for him and worse for you; and if he is ungrateful to you, it is better for you and worse for him." He asked what his view was about his property. He (peace and blessings be upon him) said: "If he dies and leaves no heir, his property is yours."
It has come like this as mursal.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الفرائض / 12382