apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r831641 - in /apr/apr/trunk: file_io/unix/open.c network_io/unix/sockets.c
Date Sun, 01 Nov 2009 06:01:01 GMT
Author: bojan
Date: Sun Nov  1 06:01:01 2009
New Revision: 831641

URL: http://svn.apache.org/viewvc?rev=831641&view=rev
Log:
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/trunk/file_io/unix/open.c
    apr/apr/trunk/network_io/unix/sockets.c

Modified: apr/apr/trunk/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/open.c?rev=831641&r1=831640&r2=831641&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/open.c (original)
+++ apr/apr/trunk/file_io/unix/open.c Sun Nov  1 06:01:01 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/trunk/network_io/unix/sockets.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sockets.c?rev=831641&r1=831640&r2=831641&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sockets.c (original)
+++ apr/apr/trunk/network_io/unix/sockets.c Sun Nov  1 06:01:01 2009
@@ -38,6 +38,12 @@
 static apr_status_t socket_cleanup(void *sock)
 {
     apr_socket_t *thesocket = sock;
+    int sd = thesocket->socketdes;
+
+    /* 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 APR_HAVE_SOCKADDR_UN
     if (thesocket->bound && thesocket->local_addr->family == APR_UNIX) {
@@ -45,11 +51,13 @@
         unlink(thesocket->local_addr->hostname);
     }
 #endif        
-    if (close(thesocket->socketdes) == 0) {
-        thesocket->socketdes = -1;
+    if (close(sd) == 0) {
         return APR_SUCCESS;
     }
     else {
+        /* Restore, close() was not successful. */
+        thesocket->socketdes = sd;
+
         return errno;
     }
 }



Mime
View raw message