use getcwd instead of get_current_dir_name
fix memory leaks