summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/cygheap.h7
-rw-r--r--winsup/cygwin/dtable.cc23
-rw-r--r--winsup/cygwin/dtable.h4
-rw-r--r--winsup/cygwin/syscalls.cc4
5 files changed, 19 insertions, 28 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 5b2ed1468..c187e3297 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,14 @@
2012-01-22 Christopher Faylor <me.cygwin2012@cgf.cx>
+ * cygheap.h (cygheap_fdmanip::release): Simplify.
+ * dtable.cc (dtable::release): Make void again. Skip not_open check
+ since it is guaranteed to be open. Don't bother deleting here since
+ actual deletion will be handled in cygheap_fdget::~cygheap_fdget.
+ * dtable.h (dtable::release): Make void again.
+ * syscalls.cc (dup2): Bump fhandler use count on successful dup.
+
+2012-01-22 Christopher Faylor <me.cygwin2012@cgf.cx>
+
* cygheap.h (cygheap_fdget::~cygheap_fdget): Simplify now that refcnt
reports reference count changes itself.
* fhandler.cc (fhandler_base::reset): Set _refcnt to 0.
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index 3bba1ae9f..2c9077ada 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -407,12 +407,7 @@ public:
delete fh;
}
}
- void release ()
- {
- fh = cygheap->fdtab[fd];
- if (cygheap->fdtab.release (fd))
- fh = NULL;
- }
+ void release () { cygheap->fdtab.release (fd); }
};
class cygheap_fdenum : public cygheap_fdmanip
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index a47a77d98..ba0045f9e 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -237,26 +237,13 @@ dtable::find_unused_handle (int start)
return -1;
}
-bool
+void
dtable::release (int fd)
{
- bool deleted;
- if (not_open (fd))
- deleted = false;
- else
- {
- if (fds[fd]->need_fixup_before ())
- dec_need_fixup_before ();
- if (fds[fd]->refcnt (-1) > 0)
- deleted = false;
- else
- {
- deleted = true;
- delete fds[fd];
- }
- fds[fd] = NULL;
- }
- return deleted;
+ if (fds[fd]->need_fixup_before ())
+ dec_need_fixup_before ();
+ fds[fd]->refcnt (-1);
+ fds[fd] = NULL;
}
extern "C" int
diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h
index cab9ac577..d0065f421 100644
--- a/winsup/cygwin/dtable.h
+++ b/winsup/cygwin/dtable.h
@@ -1,7 +1,7 @@
/* dtable.h: fd table definition.
Copyright 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
- 2010, 2011 Red Hat, Inc.
+ 2010, 2011, 2012 Red Hat, Inc.
This file is part of Cygwin.
@@ -63,7 +63,7 @@ public:
}
int find_unused_handle (int start);
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
- bool release (int fd) __attribute__ ((regparm (2)));
+ void release (int fd) __attribute__ ((regparm (2)));
void init_std_file_from_handle (int fd, HANDLE handle);
int dup3 (int oldfd, int newfd, int flags);
void fixup_after_exec ();
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 42c1924f5..350c762b5 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -139,8 +139,8 @@ dup2 (int oldfd, int newfd)
cygheap_fdget cfd (oldfd);
res = (cfd >= 0) ? oldfd : -1;
}
- else
- res = cygheap->fdtab.dup3 (oldfd, newfd, 0);
+ else if ((res = cygheap->fdtab.dup3 (oldfd, newfd, 0)) == newfd)
+ cygheap->fdtab[newfd]->refcnt (1);
syscall_printf ("%R = dup2(%d, %d)", res, oldfd, newfd);
return res;