Imam al-Sha'bi (may Allah have mercy on him) said: The case of a man was brought before Judge Shurayh (may Allah have mercy on him): he had married a slave woman and she bore him children, then he bought her. Judge Shurayh (may Allah have mercy on him) referred the case to Ubaydah (may Allah have mercy on him), and Ubaydah (may Allah have mercy on him) said: "An umm walad is freed only when she bore the children free; when she bore them as slaves, she is not freed."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب عتق أمهات الأولاد / 21805