]> sourceware.org Git - newlib-cygwin.git/commitdiff
* dtable.cc (dtable::dup_worker): Add comment explaining why refcnt isn't
authorChristopher Faylor <me@cgf.cx>
Wed, 1 Feb 2012 17:20:02 +0000 (17:20 +0000)
committerChristopher Faylor <me@cgf.cx>
Wed, 1 Feb 2012 17:20:02 +0000 (17:20 +0000)
incremented here.
(dtable::dup3): Simplify slightly.  Add comment.
* syscalls.cc (dup3): Increment refcnt here, similarly to dup2.

winsup/cygwin/ChangeLog
winsup/cygwin/dtable.cc
winsup/cygwin/syscalls.cc

index 384c99be5c45fc00197a235c033bcd585b5d0703..a774fee020048a58644677b53de05fcbb9505f40 100644 (file)
@@ -1,3 +1,10 @@
+2012-02-01  Christopher Faylor  <me.cygwin2012@cgf.cx>
+
+       * dtable.cc (dtable::dup_worker): Add comment explaining why refcnt
+       isn't incremented here.
+       (dtable::dup3): Simplify slightly.  Add comment.
+       * syscalls.cc (dup3): Increment refcnt here, similarly to dup2.
+
 2012-02-01  Christopher Faylor  <me.cygwin2012@cgf.cx>
 
        * fhandler.cc (fhandler_base_overlapped::has_ongoing_io): Don't block
index ba0045f9efac9b5d0e38cf70b24e4fcef2af3b2d..c0af76961e53124a019a1664258eb80f6701caee 100644 (file)
@@ -669,8 +669,12 @@ dtable::dup_worker (fhandler_base *oldfh, int flags)
        }
       else
        {
+         /* Don't increment refcnt here since we don't know if this is a
+            allocated fd.  So we leave this chore to the caller. */
+
          newfh->usecount = 0;
          newfh->archetype_usecount (1);
+
          /* The O_CLOEXEC flag enforces close-on-exec behaviour. */
          newfh->set_close_on_exec (!!(flags & O_CLOEXEC));
          debug_printf ("duped '%s' old %p, new %p", oldfh->get_name (), oldfh->get_io_handle (), newfh->get_io_handle ());
@@ -735,9 +739,9 @@ dtable::dup3 (int oldfd, int newfd, int flags)
 
   if (!not_open (newfd))
     close (newfd);
-  else if ((size_t) newfd < size)
-    /* nothing to do */;
-  else if (find_unused_handle (newfd) < 0)
+  else if ((size_t) newfd > size
+          && find_unused_handle (newfd) < 0)
+    /* couldn't extend fdtab */
     {
       newfh->close ();
       res = -1;
index 4ff64a3e39f33f088381bfc495d176dbb2464734..3ed0f4f9509fab4e1573e09b81a13efee52e31d8 100644 (file)
@@ -161,8 +161,9 @@ dup3 (int oldfd, int newfd, int flags)
       set_errno (cfd < 0 ? EBADF : EINVAL);
       res = -1;
     }
-  else
-    res = cygheap->fdtab.dup3 (oldfd, newfd, flags);
+  else if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags)) == newfd)
+    cygheap->fdtab[newfd]->refcnt (1);
+
   syscall_printf ("%R = dup3(%d, %d, %p)", res, oldfd, newfd, flags);
   return res;
 }
This page took 0.036644 seconds and 5 git commands to generate.