From 6763399ef3f268269fefd75d7c7a4ac012f66833 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 18 Aug 2017 23:52:19 -0700 Subject: [PATCH] Fix recently-introduced file descriptor leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/fileio.c (Fmake_temp_file_internal): Don’t leak a file descriptor if write_region signals an error. --- src/fileio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fileio.c b/src/fileio.c index 6b3bdf2154d..f954ac12b5d 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -693,10 +693,14 @@ This function does not grok magic file names. */) bool failed = fd < 0; if (!failed) { + ptrdiff_t count = SPECPDL_INDEX (); + record_unwind_protect_int (close_file_unwind, fd); val = DECODE_FILE (val); if (STRINGP (text) && SBYTES (text) != 0) write_region (text, Qnil, val, Qnil, Qnil, Qnil, Qnil, fd); failed = NILP (dir_flag) && emacs_close (fd) != 0; + /* Discard the unwind protect. */ + specpdl_ptr = specpdl + count; } if (failed) { -- 2.39.2