Mothballs in the pantry: is it safe to keep food there?
Mothballs work by sublimating (evaporating) a toxic substance into the air. That substance, be it para-dichlorobenzene or napthalene, recondenses on whatever else is in the area around them, and makes those objects toxic to moths etc.
However, the sublimation takes a long time. You can leave mothballs in a closet for months, and still not see very little weight loss in the balls themselves. That means that not much will come off in 'a few hours' to wreck your food.
Tell your roommate that a pantry is not a good long term storage spot for mothballs, but eat the food with confidence. It hasn't had time to get contaminated.