When DOSBox is closed while playing MIDI, the last active note(s) may continue to be played (indefinitely) by the external device or software.
The attached patch inserts commands to stop all MIDI voices and controllers on shutdown.
Thanks to user @BPaden on GitHub for assisting with this work.