Abu Salamah bin Abdur Rahman narrated that Ibn Abbas and Abu Hurairah (may Allah be pleased with them) were asked about a pregnant woman whose husband passes away. Ibn Abbas said, "She must observe the longer of the two waiting periods." And Abu Hurairah (may Allah be pleased with him) said, "When she gives birth, her waiting period is over." Then Abu Salamah went to Umm al-Mu'mineen Umm Salamah (may Allah be pleased with her) and asked her about this issue. She said that Subai'ah al-Aslamiyyah (may Allah be pleased with her) gave birth half a month after her husband's death. Two men sent her marriage proposals—one was young and the other was middle-aged. She sent a proposal to the young man. The middle-aged man said, "Your waiting period is not over yet," and her family was away. That man hoped that when her family returned, they would give him preference over the young man. When she came to the Messenger of Allah (ﷺ), he said: "Your waiting period is over; you may marry whomever you wish."
Hadith Referenceمسند الإمام الشافعي / كتاب العدد والسكنى والنفقات / 1301
Hadith Takhrijاخرجه النسائي الطلاق، باب عدة الحاحل المتوفى عنها زوجها (3540) - واحمد : 6 / 319- وصححه ابن حبان۔