SERVER-5932 Fix use after free

BuildBot ticket: SERVER-10200