Sayyiduna Abdullah bin Zayd (may Allah be pleased with him) says that a complaint was made to the Prophet (peace and blessings be upon him) about a man who imagines something during the prayer, and he (peace and blessings be upon him) said: "He should not turn away until he hears a sound or finds a smell."
(b) Imam al-Shafi'i (may Allah have mercy on him) says that when wind is passed, leaving the prayer is the Sunnah; and this is also like (the passing of) urine and stool.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 555