It happened in two battles if I remember correctly. I think they were at the Beach area next to the starting town.
I'm in the first gym at the moment and I don't think I've had it happen to me in there yet.
Edit: Also, if you try to use a Big Malasada on a Pokemon in battle it just brings you back to the bag screen. (without doing anything)