Fix remaining invalid frees in HMM
issue #1625