[newlib-cygwin/cygwin-3_6-branch] Cygwin: open: Add missing unlock on error

Takashi Yano via Cygwin-cvs <[email protected]> Mon, 3 Aug 2026 10:48:54 +0000 (GMT)
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D5891530ed92=
78b8144fd225f907c638e027d8281

commit 5891530ed9278b8144fd225f907c638e027d8281
Author: Takashi Yano <[email protected]>
Date:   Mon Aug 3 12:11:20 2026 +0900

    Cygwin: open: Add missing unlock on error
   =20
    the commit 524d75ff7398 ("Cygwin: open: Unlock fdtab before open_
    with_arch()") introduced a bug that fdtab lock was not unlocked
    when new fd cannot be allocated due to an error.
   =20
    This patch adds missing unlock for fdtab lock on error.
   =20
    Fixes: 524d75ff7398 ("Cygwin: open: Unlock fdtab before open_with_arch(=
)")
    Suggested-by: Johannes Schindelin <[email protected]>
    Signed-off-by: Takashi Yano <[email protected]>
    Reviewed-by: Mark Geisert <[email protected]>
    (cherry picked from commit 10d2abae386c8c5937b04d42e4cae862066347f7)

Diff:
---
 winsup/cygwin/syscalls.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index e3ba8c65c..5465d6c09 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1554,7 +1554,10 @@ open (const char *unix_path, int flags, ...)
       cygheap->fdtab.lock();
       fd =3D cygheap->fdtab.find_unused_handle ();
       if (fd < 0)
-	__leave;		/* errno already set */
+	{
+	  cygheap->fdtab.unlock ();
+	  __leave;		/* errno already set */
+	}
       cygheap->fdtab[fd] =3D fh; /* tentative setting to mark as used */
       cygheap->fdtab.unlock();