summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-12-31 10:06:43 +0000
committerJim Meyering <jim@meyering.net>2004-12-31 10:06:43 +0000
commit0a872de7cdea50a4194b69fba86f16c2f0d14af3 (patch)
tree6007318011d397d7bb9f9dbf2f706f8aa6ae95de /lib
parent53ed4aabb6cbab7ee4760ba69036458900f0a9c8 (diff)
downloadcoreutils-0a872de7cdea50a4194b69fba86f16c2f0d14af3.tar.xz
(rpl_openat): Correct comment.
Call free_cwd, to avoid leaking a file descriptor.
Diffstat (limited to 'lib')
-rw-r--r--lib/openat.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/openat.c b/lib/openat.c
index 26e280d78..fa617b807 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -37,7 +37,11 @@
/* Replacement for Solaris' openat function.
<http://www.google.com/search?q=openat+site:docs.sun.com>
Simulate it by doing save_cwd/fchdir/open/restore_cwd.
- If either the fchdir or the restore_cwd fails, then exit nonzero. */
+ If either the save_cwd or the restore_cwd fails (relatively unlikely,
+ and usually indicative of a problem that deserves close attention),
+ then give a diagnostic and exit nonzero.
+ Otherwise, upon failure, set errno and return -1, as openat does.
+ Upon successful completion, return a file descriptor. */
int
rpl_openat (int fd, char const *filename, int flags, ...)
{
@@ -80,6 +84,8 @@ rpl_openat (int fd, char const *filename, int flags, ...)
error (exit_failure, errno,
_("openat: unable to restore working directory"));
+ free_cwd (&saved_cwd);
+
errno = saved_errno;
return new_fd;
}