Haha, I've had a close call similar to that. Nothing fell out of my pocket or anything, but my Junior year in High School my school didn't have as much of a drug problem as this year, so everyone who had shit was pretty laid back and a lot of times I would just buy weed in the bathroom from a friend and just keep it in my pocket in an altoid tin.
Well, during my last class we had a test and it turned out she caught someone with a cheat sheet, so after class as everyone was walking out she had everyone empty their pockets. I was actually the first one to the door so I didn't expect it, but when she said to empty my pockets I did and all I had was my keys, a pen, and of course my altoid tin filled with weed. She looked at it for a minute and then asked if I had anything in there that I shouldn't have. I almost shit myself cause I pretty much figured she'd ask me to open it, but when I said "no, there's just altoids" she said alright you can go.
Very close call there, and after that I didn't take any more chances with carrying my bud in my pockets.