bug-21026: Fix memory leak in sub state machine