summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/gen/opendir.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 4028ba9c1eb..d7c60057f06 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: opendir.c,v 1.19 2007/06/05 18:11:48 kurt Exp $ */
+/* $OpenBSD: opendir.c,v 1.20 2010/01/19 17:12:43 millert Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -62,7 +62,11 @@ __opendir2(const char *name, int flags)
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
return (NULL);
- if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
+ if (fstat(fd, &sb)) {
+ close(fd);
+ return (NULL);
+ }
+ if (!S_ISDIR(sb.st_mode)) {
close(fd);
errno = ENOTDIR;
return (NULL);
@@ -89,7 +93,7 @@ __opendir2(const char *name, int flags)
dirp->dd_buf = malloc((size_t)dirp->dd_len);
if (dirp->dd_buf == NULL) {
free(dirp);
- close (fd);
+ close(fd);
return (NULL);
}