Fix for stray jobs not getting freed. TRQ-1624. This was
ported from 4.2-dev.