[Reviewer: Andy] Prevent quadruple-free error on shutdown

Fixes https://github.com/Metaswitch/sprout/issues/674. Compiled, not tested.