fix possible double free in TextIOWrapper.__init__ (closes #22849)