From b7c42fadf71598aa23a8a78d0b85ed77a9cb5fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 17 Oct 2002 19:27:03 +0000 Subject: [PATCH] Fixed fd lead in opendir() and set errno correctly if memory is out. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1564 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/unistd/directory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/kernel/libroot/posix/unistd/directory.c b/src/kernel/libroot/posix/unistd/directory.c index f6ed899b1b..1cd66c1b36 100644 --- a/src/kernel/libroot/posix/unistd/directory.c +++ b/src/kernel/libroot/posix/unistd/directory.c @@ -34,8 +34,11 @@ opendir(const char *path) return NULL; /* allocate the memory for the DIR structure */ - if ((dir = (DIR*)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) + if ((dir = (DIR*)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) { + errno = B_NO_MEMORY; + sys_close(fd); return NULL; + } dir->fd = fd;