A thought just occurred to me: how would a soldier (lets just pick British 1815 Waterloo, but I'm interested in other time periods as well) fighting in an infantry line react to a serious malfunction of some sort in his weapon that would prevent it from being fired? Say his powder doesn't ignite properly or a spring in the lock mechanism broke?
How would he signal to his chain of command that his weapon had been rendered useless and that he had not just stopped shooting out of fear or something like that which would be punished? And how would he do so without disrupting the formation?
Generally, he's out of luck when it comes to firing again. The ability to fix your musket in the middle of battle would be hampered by the movement and demands of battle, thus they would have to wait until the battalion moves in order to easily move behind if they were going to be allowed to move. They wouldn't be able to signal any officers and generally by the Napoleonic era, most soldiers would be able to fight without fear of punishment for anything. Even during the earlier 18th century, weapon malfunction wasn't the end of the world for a soldier.
Most importantly, they would stay in formation to not mess everyone up in their ability to fire (as soldiers behind them would still be firing) but also since they can still fight if necessary with their bayonet.
If the number of double, triple, and quadruple-loaded rifles recovered at Gettysburg is any indication, the soldier may have just continued with the motions of loading the weapon. They may have not even realized the main charge hadn't fired. Particularly with flint and matchlock rifles, the priming charge is quite noticeable and distracting, more so than the main charge. (The other interpretation is that some of those men couldn't bring themselves to pull the trigger, so just kept reloading).
In particular, with reference to musketmen and tactics in the Napoleonic time period, in many cases there would only have been one or two volleys fired before the bayonet charge. The inaccuracy of the musket meant that only a point-blank volley was effective, so the lines waited last moment to fire (Hence the famous line, "Don't fire until you see the whites of their eyes!"). So a soldier with a inoperable weapon wouldn't be much of a problem, as he'd only miss one or two shots, and never have time to fix it.