Fix memory violation in delayed close