Subject: bug#22814: 25.0.91; Emacs runs out of file descriptors on OS X

From: Paul Eggert <[email-masked]>
Date: Fri, 4 Mar 2016 16:32:37 -0800

> +   if ((errno == EMFILE) || (errno == ENFILE))
> + 	report_file_error ("Read error on documentation file", file);

This new code should be after the 2nd call to 'emacs_open', not after the 1st. 
The difference is unlikely to matter, but still.... I installed the attached 
further patch.
>From d5e42616a0b5c0b0f0d1b01982d7b949bf8ddc0d Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 4 Mar 2016 16:29:55 -0800
Subject: [PATCH] doc string file descriptor exhaustion fix

* src/doc.c (get_doc_string): Move newly-added check to a better
location (Bug#22814).
---
 src/doc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/doc.c b/src/doc.c
index 6e79065..a20ecbd 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -126,9 +126,6 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
   fd = emacs_open (name, O_RDONLY, 0);
   if (fd < 0)
     {
-      if ((errno == EMFILE) || (errno == ENFILE))
-	report_file_error ("Read error on documentation file", file);
-
 #ifndef CANNOT_DUMP
       if (!NILP (Vpurify_flag))
 	{
@@ -141,6 +138,9 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
 #endif
       if (fd < 0)
 	{
+	  if (errno == EMFILE || errno == ENFILE)
+	    report_file_error ("Read error on documentation file", file);
+
 	  SAFE_FREE ();
 	  AUTO_STRING (cannot_open, "Cannot open doc string file \"");
 	  AUTO_STRING (quote_nl, "\"\n");
-- 
2.5.0