Sahih Muslim Book 4, Hadith Number 1149.

Chapter : When food is brought before man and he is inclined to take it, he should not say prayer before eating it and undesirability of prayer while feeling the call of nature.

Abu Sa’id reported: We made no transgression but Khaybar was conquered. We, the Companions of the Messenger of Allah (may peace be upon him), fell upon this plant. i.e. garlic. because the people were hungry. We ate it to our heart’s content and then made our way towards the mosque. The Messenger of Allah (may peace be upon him) sensed its odour and he said: He who takes anything of this offensive plant must not approach us in the mosque. The people said: Its (use) has been forbidden; its (use) has been forbidden. This reached the Apostle of Allah (may peace be upon him) and he said: O people, I cannot forbid (the use of a thing) which Allah has made lawful, but (this garlic) is a plant the odour of which is repugnant to me.