[Machine] The Messenger of Allah ﷺ said: "If one of you feels the need to pass gas, he should not leave until he hears a sound or smells a scent that indicates he has passed gas." This narration is found in the book of Muslim, in a hadith narrated by Jarir bin Abdullah from Suhail bin Abu Salih. And it is mentioned in the hadith that they should not leave the mosque.
قَالَ رَسُولُ اللهِ ﷺ إِذَا وَجَدَ أَحَدُكُمْ فِي بَطْنِهِ الرِّيحَ فُخُيِّلَ إِلَيْهِ أَنَّهُ خَرَجَ مِنْهُ الشَّيْءُ فَلَا يَخْرُجْ حَتَّى يَسْمَعَ صَوْتًا أَوْ يَجِدَ رِيحًا مُخَرَّجٌ فِي كِتَابِ مُسْلِمٍ مِنْ حَدِيثِ جَرِيرِ بْنِ عَبْدِ الْحَمِيدِ عَنْ سُهَيْلِ بْنِ أَبِي صَالِحٍ وَقَالَ فِي الْحَدِيثِ فَلَا يَخْرُجَّنَ مِنَ الْمَسْجِدِ