Don't leak dotfd if fchdir fails. From ettl dot martin78 at gmail dot com.

This commit is contained in:
Nicholas Marriott 2015-06-10 15:39:23 +01:00
parent 02a848d77c
commit dca084e703

View File

@ -40,8 +40,12 @@ openat(int fd, const char *path, int flags, ...)
dotfd = open(".", O_RDONLY);
if (dotfd == -1)
return (-1);
if (fchdir(fd) != 0)
if (fchdir(fd) != 0) {
saved_errno = errno;
close(dotfd);
errno = saved_errno;
return (-1);
}
}
retval = open(path, flags, mode);