Fixes findAndModify memory leak on errors