From 6f830e08193b09eba3cbc5cf2789d76bc57df53d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Wed, 22 Jan 1997 10:56:29 +0100
Subject: [PATCH] Moved the error() calls out from THREADS_ALLOW/DISALLOW.

Rev: src/modules/files/efuns.c:1.9
---
 src/modules/files/efuns.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/modules/files/efuns.c b/src/modules/files/efuns.c
index a70dc95e61..a92ff6567e 100644
--- a/src/modules/files/efuns.c
+++ b/src/modules/files/efuns.c
@@ -189,12 +189,14 @@ void f_get_dir(INT32 args)
       struct dirent *tmp;
       int num_files=0;
       char *bufptr=buffer;
-      THREADS_ALLOW();
 
-      if (!(tmp = alloca(pathconf(path, _PC_NAME_MAX) + 1))) {
+      if (!(tmp = alloca(sizeof(struct dirent) + 
+			 pathconf(path, _PC_NAME_MAX) + 1))) {
 	error("get_dir(): Out of memory!\n");
       }
 
+      THREADS_ALLOW();
+
       while(1)
       {
 	/* Should have code for the POSIX variant here also */
@@ -202,7 +204,7 @@ void f_get_dir(INT32 args)
 	  d=readdir_r(dir, tmp);
 	} while ((!d) && ((errno == EAGAIN)||(errno == EINTR)));
 	if (!d) {
-	  error("get_dir(): readdir_r() failed: %d\n", errno);
+	  break;
 	}
 	if(d->d_name[0]=='.')
 	{
@@ -218,6 +220,9 @@ void f_get_dir(INT32 args)
 	num_files++;
       }
       THREADS_DISALLOW();
+      if (!d) {
+	error("get_dir(): readdir_r() failed: %d\n", errno);
+      }
       for(e=0;e<num_files;e++)
       {
 	push_string(make_shared_binary_string(ptrs[e],lens[e]));
-- 
GitLab