summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-12 15:44:14 +0000
committerJim Meyering <jim@meyering.net>2003-07-12 15:44:14 +0000
commit21f65c951c0014e18d2300a81231ece53b31f83d (patch)
tree6b2ae8efd09af9855d5665c1dcb71bfcd2cabb20 /src
parent354996bc0981ca35e20a9285ed0c35fd53a2ba9e (diff)
downloadcoreutils-21f65c951c0014e18d2300a81231ece53b31f83d.tar.xz
(find_mount_point): Don't let free clobber errno upon failed chdir
Diffstat (limited to 'src')
-rw-r--r--src/df.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/df.c b/src/df.c
index 136d32532..878764e41 100644
--- a/src/df.c
+++ b/src/df.c
@@ -433,7 +433,8 @@ show_dev (const char *disk, const char *mount_point, const char *fstype,
}
/* Return the root mountpoint of the filesystem on which FILE exists, in
- malloced storage. FILE_STAT should be the result of stating FILE. */
+ malloced storage. FILE_STAT should be the result of stating FILE.
+ Return NULL if unable to determine the mount point. */
static char *
find_mount_point (const char *file, const struct stat *file_stat)
{
@@ -455,11 +456,13 @@ find_mount_point (const char *file, const struct stat *file_stat)
/* FILE is some other kind of file, we need to use its directory. */
{
char *dir = dir_name (file);
- int rv = chdir (dir);
- free (dir);
-
- if (rv < 0)
- return NULL;
+ if (chdir (dir) < 0)
+ {
+ int saved_errno = errno;
+ free (dir);
+ errno = saved_errno;
+ return NULL;
+ }
if (stat (".", &last_stat) < 0)
goto done;