]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: fhandler_base: Fix double free caused when open() fails.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Tue, 18 Jan 2022 13:17:37 +0000 (22:17 +0900)
committerTakashi Yano <takashi.yano@nifty.ne.jp>
Tue, 18 Jan 2022 13:17:37 +0000 (22:17 +0900)
- When open fails, archetype stored in archetypes[] is not cleared.
  This causes double free when next open fail. This patch fixes the
  issue.

Addresses:
  https://cygwin.com/pipermail/cygwin/2022-January/250518.html

winsup/cygwin/fhandler.cc
winsup/cygwin/release/3.3.4

index fc7c0422ee1e39a88b57e6d8f280214b8d8f0e1d..7d427135e5e732eb86f0380679b92e63ba8569e9 100644 (file)
@@ -440,8 +440,8 @@ fhandler_base::open_with_arch (int flags, mode_t mode)
   if (!(res = (archetype && archetype->io_handle)
        || open (flags, mode & 07777)))
     {
-      if (archetype)
-       delete archetype;
+      if (archetype && archetype->usecount == 0)
+       cygheap->fdtab.delete_archetype (archetype);
     }
   else if (archetype)
     {
index e09ffefdf0d64c2d05165f9a1558930639dd44c5..3fa9b9e9c99a04816a229a6d83e8cc3f31aca4d9 100644 (file)
@@ -30,3 +30,6 @@ Bug Fixes
 - Fix a problem creating a dir "foo", if a file (but not a Cygwin symlink)
   "foo.lnk" already exists.
   Addresses: https://github.com/msys2/msys2-runtime/issues/81
+
+- Fix double free for archetype, which is caused when open() fails.
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-January/250518.html
This page took 0.03306 seconds and 5 git commands to generate.