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

Shouldn't a `return` be here?