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>
+
+ * 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
}
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 ());
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;
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;
}