Fix refcounting bug in StdIO