apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r834029 - in /apr/apr/trunk/poll/unix: pollcb.c pollset.c
Date Mon, 09 Nov 2009 12:18:11 GMT
Author: trawick
Date: Mon Nov  9 12:18:11 2009
New Revision: 834029

URL: http://svn.apache.org/viewvc?rev=834029&view=rev
Log:
apr_pollset_create_ex(), apr_pollcb_create_ex():

simplify logic to update the caller's pollcb/pollset ptr,
fixing a apr_pollcb_create_ex() crash in one of the 
fall-back paths which was reported by Neil Conway

Modified:
    apr/apr/trunk/poll/unix/pollcb.c
    apr/apr/trunk/poll/unix/pollset.c

Modified: apr/apr/trunk/poll/unix/pollcb.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/pollcb.c?rev=834029&r1=834028&r2=834029&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/pollcb.c (original)
+++ apr/apr/trunk/poll/unix/pollcb.c Mon Nov  9 12:18:11 2009
@@ -72,21 +72,23 @@
     return provider;
 }
 
-APR_DECLARE(apr_status_t) apr_pollcb_create_ex(apr_pollcb_t **pollcb,
+APR_DECLARE(apr_status_t) apr_pollcb_create_ex(apr_pollcb_t **ret_pollcb,
                                                apr_uint32_t size,
                                                apr_pool_t *p,
                                                apr_uint32_t flags,
                                                apr_pollset_method_e method)
 {
     apr_status_t rv;
+    apr_pollcb_t *pollcb;
     apr_pollcb_provider_t *provider = NULL;
 
+    *ret_pollcb = NULL;
+
     if (method == APR_POLLSET_DEFAULT)
         method = pollset_default_method;
     while (provider == NULL) {
         provider = pollcb_provider(method);
         if (!provider) {
-            *pollcb = NULL;
             if ((flags & APR_POLLSET_NODEFAULT) == APR_POLLSET_NODEFAULT)
                 return APR_ENOTIMPL;
             if (method == pollset_default_method)
@@ -95,15 +97,14 @@
         }
     }
 
-    *pollcb = apr_palloc(p, sizeof(**pollcb));
-    (*pollcb)->nelts = 0;
-    (*pollcb)->nalloc = size;
-    (*pollcb)->pool = p;
-    (*pollcb)->provider = provider;
+    pollcb = apr_palloc(p, sizeof(*pollcb));
+    pollcb->nelts = 0;
+    pollcb->nalloc = size;
+    pollcb->pool = p;
+    pollcb->provider = provider;
 
-    rv = (*provider->create)(*pollcb, size, p, flags);
+    rv = (*provider->create)(pollcb, size, p, flags);
     if (rv == APR_ENOTIMPL) {
-        *pollcb = NULL;
         if (method == pollset_default_method) {
             return rv;
         }
@@ -117,13 +118,14 @@
         if (!provider) {
             return APR_ENOTIMPL;
         }
-        rv = (*provider->create)(*pollcb, size, p, flags);
+        rv = (*provider->create)(pollcb, size, p, flags);
         if (rv != APR_SUCCESS) {
             return rv;
         }
-        (*pollcb)->provider = provider;
+        pollcb->provider = provider;
     }
 
+    *ret_pollcb = pollcb;
     return APR_SUCCESS;
 }
 

Modified: apr/apr/trunk/poll/unix/pollset.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/pollset.c?rev=834029&r1=834028&r2=834029&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/pollset.c (original)
+++ apr/apr/trunk/poll/unix/pollset.c Mon Nov  9 12:18:11 2009
@@ -210,21 +210,23 @@
     return provider;
 }
 
-APR_DECLARE(apr_status_t) apr_pollset_create_ex(apr_pollset_t **pollset,
+APR_DECLARE(apr_status_t) apr_pollset_create_ex(apr_pollset_t **ret_pollset,
                                                 apr_uint32_t size,
                                                 apr_pool_t *p,
                                                 apr_uint32_t flags,
                                                 apr_pollset_method_e method)
 {
     apr_status_t rv;
+    apr_pollset_t *pollset;
     apr_pollset_provider_t *provider = NULL;
 
+    *ret_pollset = NULL;
+
     if (method == APR_POLLSET_DEFAULT)
         method = pollset_default_method;
     while (provider == NULL) {
         provider = pollset_provider(method);
         if (!provider) {
-            *pollset = NULL;
             if ((flags & APR_POLLSET_NODEFAULT) == APR_POLLSET_NODEFAULT)
                 return APR_ENOTIMPL;
             if (method == pollset_default_method)
@@ -237,41 +239,39 @@
         size++;
     }
 
-    *pollset = apr_palloc(p, sizeof(**pollset));
-    (*pollset)->nelts = 0;
-    (*pollset)->nalloc = size;
-    (*pollset)->pool = p;
-    (*pollset)->flags = flags;
-    (*pollset)->provider = provider;
+    pollset = apr_palloc(p, sizeof(*pollset));
+    pollset->nelts = 0;
+    pollset->nalloc = size;
+    pollset->pool = p;
+    pollset->flags = flags;
+    pollset->provider = provider;
 
-    rv = (*provider->create)(*pollset, size, p, flags);
+    rv = (*provider->create)(pollset, size, p, flags);
     if (rv == APR_ENOTIMPL) {
         if (method == pollset_default_method) {
-            *pollset = NULL;
             return rv;
         }
         provider = pollset_provider(pollset_default_method);
         if (!provider) {
-            *pollset = NULL;
             return APR_ENOTIMPL;
         }
-        rv = (*provider->create)(*pollset, size, p, flags);
+        rv = (*provider->create)(pollset, size, p, flags);
         if (rv != APR_SUCCESS) {
-            *pollset = NULL;
             return rv;
         }
-        (*pollset)->provider = provider;
+        pollset->provider = provider;
     }
     if (flags & APR_POLLSET_WAKEABLE) {
         /* Create wakeup pipe */
-        if ((rv = create_wakeup_pipe(*pollset)) != APR_SUCCESS) {
-            *pollset = NULL;
+        if ((rv = create_wakeup_pipe(pollset)) != APR_SUCCESS) {
             return rv;
         }
     }
     if ((flags & APR_POLLSET_WAKEABLE) || provider->cleanup)
-        apr_pool_cleanup_register(p, *pollset, pollset_cleanup,
+        apr_pool_cleanup_register(p, pollset, pollset_cleanup,
                                   apr_pool_cleanup_null);
+
+    *ret_pollset = pollset;
     return APR_SUCCESS;
 }
 



Mime
View raw message