It doesn't work like that. Fresh air is taken from engine continuously and old air is thrown out of the cabin through exhaust located near tail. during the flight and the whole air in the cabin is continuously filtered through HEPA filter.There are always problems. When a flight lands, the attendants at the arrival gate always try to avoid being the one who has to open the airplane door, because they are always met with a gust of farts.