Fix #204 fix leak detection bug introduced by refactor