You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2009/11/01 07:07:57 UTC
svn commit: r831642 - in /apr/apr/branches/1.4.x: ./ file_io/unix/open.c
network_io/unix/sockets.c
Author: bojan
Date: Sun Nov 1 06:07:57 2009
New Revision: 831642
URL: http://svn.apache.org/viewvc?rev=831642&view=rev
Log:
Backport r831641 from the trunk.
Set file/socket descriptor to -1 before close(), so that there is no chance
of returning an already closed FD from apr_os_file_get()/apr_os_sock_get().
Modified:
apr/apr/branches/1.4.x/ (props changed)
apr/apr/branches/1.4.x/file_io/unix/open.c
apr/apr/branches/1.4.x/network_io/unix/sockets.c
Propchange: apr/apr/branches/1.4.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 1 06:07:57 2009
@@ -1 +1 @@
-/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748988,749810,782838,783398,783958,784633,784773,788588,793192,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,829490
+/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748988,749810,782838,783398,783958,784633,784773,788588,793192,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,829490,831641
Modified: apr/apr/branches/1.4.x/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/unix/open.c?rev=831642&r1=831641&r2=831642&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/unix/open.c (original)
+++ apr/apr/branches/1.4.x/file_io/unix/open.c Sun Nov 1 06:07:57 2009
@@ -29,10 +29,14 @@
static apr_status_t file_cleanup(apr_file_t *file, int is_child)
{
apr_status_t rv = APR_SUCCESS;
+ int fd = file->filedes;
- if (close(file->filedes) == 0) {
- file->filedes = -1;
+ /* Set file descriptor to -1 before close(), so that there is no
+ * chance of returning an already closed FD from apr_os_file_get().
+ */
+ file->filedes = -1;
+ if (close(fd) == 0) {
/* Only the parent process should delete the file! */
if (!is_child && (file->flags & APR_DELONCLOSE)) {
unlink(file->fname);
@@ -44,6 +48,9 @@
#endif
}
else {
+ /* Restore, close() was not successful. */
+ file->filedes = fd;
+
/* Are there any error conditions other than EINTR or EBADF? */
rv = errno;
}
Modified: apr/apr/branches/1.4.x/network_io/unix/sockets.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/network_io/unix/sockets.c?rev=831642&r1=831641&r2=831642&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/network_io/unix/sockets.c (original)
+++ apr/apr/branches/1.4.x/network_io/unix/sockets.c Sun Nov 1 06:07:57 2009
@@ -31,12 +31,20 @@
static apr_status_t socket_cleanup(void *sock)
{
apr_socket_t *thesocket = sock;
+ int sd = thesocket->socketdes;
- if (close(thesocket->socketdes) == 0) {
- thesocket->socketdes = -1;
+ /* Set socket descriptor to -1 before close(), so that there is no
+ * chance of returning an already closed FD from apr_os_sock_get().
+ */
+ thesocket->socketdes = -1;
+
+ if (close(sd) == 0) {
return APR_SUCCESS;
}
else {
+ /* Restore, close() was not successful. */
+ thesocket->socketdes = sd;
+
return errno;
}
}