Fix memory leak in Release_io

Bring commits 354b13e..1984516 from master.