apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1666341 - in /apr/apr/trunk/poll/unix: epoll.c kqueue.c poll.c pollcb.c port.c z_asio.c
Date Fri, 13 Mar 2015 00:27:20 GMT
Author: ylavic
Date: Fri Mar 13 00:27:19 2015
New Revision: 1666341

URL: http://svn.apache.org/r1666341
Log:
apr_poll(cb): fix error paths returned values and leaks.

Modified:
    apr/apr/trunk/poll/unix/epoll.c
    apr/apr/trunk/poll/unix/kqueue.c
    apr/apr/trunk/poll/unix/poll.c
    apr/apr/trunk/poll/unix/pollcb.c
    apr/apr/trunk/poll/unix/port.c
    apr/apr/trunk/poll/unix/z_asio.c

Modified: apr/apr/trunk/poll/unix/epoll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/epoll.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/epoll.c (original)
+++ apr/apr/trunk/poll/unix/epoll.c Fri Mar 13 00:27:19 2015
@@ -106,12 +106,20 @@ static apr_status_t impl_pollset_create(
     {
         int fd_flags;
 
-        if ((fd_flags = fcntl(fd, F_GETFD)) == -1)
-            return errno;
+        if ((fd_flags = fcntl(fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(fd);
+            pollset->p = NULL;
+            return rv;
+        }
 
         fd_flags |= FD_CLOEXEC;
-        if (fcntl(fd, F_SETFD, fd_flags) == -1)
-            return errno;
+        if (fcntl(fd, F_SETFD, fd_flags) == -1) {
+            rv = errno;
+            close(fd);
+            pollset->p = NULL;
+            return rv;
+        }
     }
 #endif
 
@@ -122,11 +130,13 @@ static apr_status_t impl_pollset_create(
         ((rv = apr_thread_mutex_create(&pollset->p->ring_lock,
                                        APR_THREAD_MUTEX_DEFAULT,
                                        p)) != APR_SUCCESS)) {
+        close(fd);
         pollset->p = NULL;
         return rv;
     }
 #else
     if (flags & APR_POLLSET_THREADSAFE) {
+        close(fd);
         pollset->p = NULL;
         return APR_ENOTIMPL;
     }
@@ -347,13 +357,22 @@ static apr_status_t impl_pollcb_create(a
 #ifndef HAVE_EPOLL_CREATE1
     {
         int fd_flags;
+        apr_status_t rv;
 
-        if ((fd_flags = fcntl(fd, F_GETFD)) == -1)
-            return errno;
+        if ((fd_flags = fcntl(fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(fd);
+            pollcb->fd = -1;
+            return rv;
+        }
 
         fd_flags |= FD_CLOEXEC;
-        if (fcntl(fd, F_SETFD, fd_flags) == -1)
-            return errno;
+        if (fcntl(fd, F_SETFD, fd_flags) == -1) {
+            rv = errno;
+            close(fd);
+            pollcb->fd = -1;
+            return rv;
+        }
     }
 #endif
     

Modified: apr/apr/trunk/poll/unix/kqueue.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/kqueue.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/kqueue.c (original)
+++ apr/apr/trunk/poll/unix/kqueue.c Fri Mar 13 00:27:19 2015
@@ -115,12 +115,20 @@ static apr_status_t impl_pollset_create(
     {
         int flags;
 
-        if ((flags = fcntl(pollset->p->kqueue_fd, F_GETFD)) == -1)
-            return errno;
+        if ((flags = fcntl(pollset->p->kqueue_fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(pollset->p->kqueue_fd);
+            pollset->p = NULL;
+            return rv;
+        }
 
         flags |= FD_CLOEXEC;
-        if (fcntl(pollset->p->kqueue_fd, F_SETFD, flags) == -1)
-            return errno;
+        if (fcntl(pollset->p->kqueue_fd, F_SETFD, flags) == -1) {
+            rv = errno;
+            close(pollset->p->kqueue_fd);
+            pollset->p = NULL;
+            return rv;
+        }
     }
 
     pollset->p->result_set = apr_palloc(p, pollset->p->setsize * sizeof(apr_pollfd_t));
@@ -338,13 +346,22 @@ static apr_status_t impl_pollcb_create(a
 
     {
         int flags;
+        apr_status_t rv;
 
-        if ((flags = fcntl(fd, F_GETFD)) == -1)
-            return errno;
+        if ((flags = fcntl(fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(fd);
+            pollcb->fd = -1;
+            return rv;
+        }
 
         flags |= FD_CLOEXEC;
-        if (fcntl(fd, F_SETFD, flags) == -1)
-            return errno;
+        if (fcntl(fd, F_SETFD, flags) == -1) {
+            rv = errno;
+            close(fd);
+            pollcb->fd = -1;
+            return rv;
+        }
     }
  
     pollcb->fd = fd;

Modified: apr/apr/trunk/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/poll.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/poll.c (original)
+++ apr/apr/trunk/poll/unix/poll.c Fri Mar 13 00:27:19 2015
@@ -240,24 +240,22 @@ static apr_status_t impl_pollset_poll(ap
 {
     int ret;
     apr_status_t rv = APR_SUCCESS;
-#ifdef WIN32
-    apr_interval_time_t orig_timeout = timeout;
-#endif
 
-    if (timeout > 0) {
-        timeout /= 1000;
-    }
 #ifdef WIN32
     /* WSAPoll() requires at least one socket. */
     if (pollset->nelts == 0) {
         *num = 0;
-        if (orig_timeout > 0) {
-            apr_sleep(orig_timeout);
+        if (timeout > 0) {
+            apr_sleep(timeout);
             return APR_TIMEUP;
         }
         return APR_SUCCESS;
     }
 
+    if (timeout > 0) {
+        timeout /= 1000;
+    }
+
     ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
 #else
     ret = poll(pollset->p->pollset, pollset->nelts, timeout);

Modified: apr/apr/trunk/poll/unix/pollcb.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/pollcb.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/pollcb.c (original)
+++ apr/apr/trunk/poll/unix/pollcb.c Fri Mar 13 00:27:19 2015
@@ -156,6 +156,9 @@ APR_DECLARE(apr_status_t) apr_pollcb_cre
         }
         pollcb->provider = provider;
     }
+    else if (rv != APR_SUCCESS) {
+        return rv;
+    }
 
     if (flags & APR_POLLSET_WAKEABLE) {
         /* Create wakeup pipe */

Modified: apr/apr/trunk/poll/unix/port.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/port.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/port.c (original)
+++ apr/apr/trunk/poll/unix/port.c Fri Mar 13 00:27:19 2015
@@ -188,12 +188,20 @@ static apr_status_t impl_pollset_create(
     {
         int flags;
 
-        if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1)
-            return errno;
+        if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(pollset->p->port_fd);
+            pollset->p = NULL;
+            return rv;
+        }
 
         flags |= FD_CLOEXEC;
-        if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1)
-            return errno;
+        if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1) {
+            rv = errno;
+            close(pollset->p->port_fd);
+            pollset->p = NULL;
+            return rv;
+        }
     }
 
     pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
@@ -477,13 +485,22 @@ static apr_status_t impl_pollcb_create(a
 
     {
         int flags;
+        apr_status_t rv;
 
-        if ((flags = fcntl(pollcb->fd, F_GETFD)) == -1)
-            return errno;
+        if ((flags = fcntl(pollcb->fd, F_GETFD)) == -1) {
+            rv = errno;
+            close(pollcb->fd);
+            pollcb->fd = -1;
+            return rv;
+        }
 
         flags |= FD_CLOEXEC;
-        if (fcntl(pollcb->fd, F_SETFD, flags) == -1)
-            return errno;
+        if (fcntl(pollcb->fd, F_SETFD, flags) == -1) {
+            rv = errno;
+            close(pollcb->fd);
+            pollcb->fd = -1;
+            return rv;
+        }
     }
 
     pollcb->pollset.port = apr_palloc(p, size * sizeof(port_event_t));

Modified: apr/apr/trunk/poll/unix/z_asio.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/z_asio.c?rev=1666341&r1=1666340&r2=1666341&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/z_asio.c (original)
+++ apr/apr/trunk/poll/unix/z_asio.c Fri Mar 13 00:27:19 2015
@@ -272,7 +272,7 @@ static apr_status_t asio_pollset_create(
                                            APR_THREAD_MUTEX_DEFAULT,
                                            p) != APR_SUCCESS) {
             DBG1(1, "apr_thread_mutex_create returned %d\n", rv);
-            pollset = NULL;
+            pollset->p = NULL;
             return rv;
         }
         rv = msgget(IPC_PRIVATE, S_IWUSR+S_IRUSR); /* user r/w perms */
@@ -280,7 +280,7 @@ static apr_status_t asio_pollset_create(
 #if DEBUG
             perror(__FUNCTION__ " msgget returned < 0 ");
 #endif
-            pollset = NULL;
+            pollset->p = NULL;
             return rv;
         }
 
@@ -292,7 +292,7 @@ static apr_status_t asio_pollset_create(
         APR_RING_INIT(&priv->prior_ready_ring, asio_elem_t, link);
 
 #else  /* APR doesn't have threads but caller wants a threadsafe pollset */
-        pollset = NULL;
+        pollset->p = NULL;
         return APR_ENOTIMPL;
 #endif
 
@@ -304,6 +304,7 @@ static apr_status_t asio_pollset_create(
         priv->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
 
         if ((!priv->pollset) || (!priv->query_set)) {
+            pollset->p = NULL;
             return APR_ENOMEM;
         }
     }
@@ -314,6 +315,10 @@ static apr_status_t asio_pollset_create(
     priv->size    = size;
     priv->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
     if (!priv->result_set) {
+        if (flags & APR_POLLSET_THREADSAFE) {
+            msgctl(priv->msg_q, IPC_RMID, NULL);
+        }
+        pollset->p = NULL;
         return APR_ENOMEM;
     }
 



Mime
View raw message