From 423849f74d0d84cec4eb2a53da5b6f0cea4c36ee Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 25 Dec 2002 04:38:50 +0000 Subject: [PATCH] Partly revert the last change - low-level chdir actually writes to the "directory" argument, so preserve it. --- vfs/vfs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vfs/vfs.c b/vfs/vfs.c index 5cac96b77..dc8ecbd80 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -883,17 +883,23 @@ vfs_add_current_stamps (void) int mc_chdir (char *path) { - char *new_dir; + char *new_dir, *new_dir_copy; vfs *old_vfs, *new_vfs; vfsid old_vfsid; struct vfs_stamping *parent; + int result; new_dir = vfs_canon (path); new_vfs = vfs_type (new_dir); if (!new_vfs->chdir) vfs_die ("No chdir function defined"); - if ((*new_vfs->chdir) (new_vfs, new_dir) == -1) { + /* new_vfs->chdir can write to the second argument, use a copy */ + new_dir_copy = g_strdup (new_dir); + result = (*new_vfs->chdir) (new_vfs, new_dir_copy); + g_free (new_dir_copy); + + if (result == -1) { errno = ferrno (new_vfs); g_free (new_dir); return -1; @@ -907,7 +913,7 @@ mc_chdir (char *path) current_dir = new_dir; current_vfs = new_vfs; - /* This function uses current_dir internally */ + /* This function uses the new current_dir implicitly */ vfs_add_noncurrent_stamps (old_vfs, old_vfsid, parent); vfs_rm_parents (parent);