Fix 2 refcounting bugs in StdIO