Al-Sha'bi narrates from Sayyiduna Ali (may Allah be pleased with him): When a woman frees a male or female slave, then she dies and leaves a male child, the wala' of that freed slave belongs to her children as long as they are male. When the male children come to an end, the wala' returns to her awliya' (agnatic relatives).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الولاء / 21498