Fixed memory leak in change cwd