Rarely, but sometimes, there is a mechanical failure. There are 3 safeties on a Glock, but there's a very, very, very remote chance that the discharge wasn't from operator error.
With an older 1911, rack the slide, finger off trigger, grip safety obviously disengaged, and release slide just before cocked position. The gun will go bang.