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

Ok, sounds good!