Fix bugs found by clang analyzer

When we were generating an exception for IO::open, the path was never
freed and would leak. This fixes it by making sure we mark the original
string as on stack and use that for the exception message.

Also makes sure we mark the current IO as on stack in IO::reopen_path so
we refer to the correct object if we set the mode after the open call.
Also makes sure that we get the buffer through a potentially updated
pointer.
Just initialize variables to 0

This was attempting to not initialize variables, by setting it to itself
with undefined values. Just setting it to 0 seems like a much simpler
solution here.