libstd: refine dynamic memory allocations in os::getcwd() and os::change_dir()

Oh that may be OSX-specific...