You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2010/06/05 22:43:15 UTC

svn commit: r951762 - in /apr/apr/trunk: buckets/apr_brigade.c include/apr_buckets.h

Author: jorton
Date: Sat Jun  5 20:43:15 2010
New Revision: 951762

URL: http://svn.apache.org/viewvc?rev=951762&view=rev
Log:
Add debugging traps for use-after-destroy of a brigade:

* buckets/apr_brigade.c (apr_brigade_cleanup): Check brigade
  consistency.

  (apr_brigade_destroy) [APR_BUCKET_DEBUG]: Check brigade consistency
  before destroying it, and clear b->p, b->bucket_alloc after.

* include/apr_buckets.h (APR_BRIGADE_CHECK_CONSISTENCY): assert that
  b->p and b->bucket_alloc are non-NULL.

Suggested by: sf

Modified:
    apr/apr/trunk/buckets/apr_brigade.c
    apr/apr/trunk/include/apr_buckets.h

Modified: apr/apr/trunk/buckets/apr_brigade.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/buckets/apr_brigade.c?rev=951762&r1=951761&r2=951762&view=diff
==============================================================================
--- apr/apr/trunk/buckets/apr_brigade.c (original)
+++ apr/apr/trunk/buckets/apr_brigade.c Sat Jun  5 20:43:15 2010
@@ -39,6 +39,8 @@ APR_DECLARE(apr_status_t) apr_brigade_cl
     apr_bucket_brigade *b = data;
     apr_bucket *e;
 
+    APR_BRIGADE_CHECK_CONSISTENCY(b);
+
     while (!APR_BRIGADE_EMPTY(b)) {
         e = APR_BRIGADE_FIRST(b);
         apr_bucket_delete(e);
@@ -49,8 +51,22 @@ APR_DECLARE(apr_status_t) apr_brigade_cl
 
 APR_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b)
 {
-    apr_pool_cleanup_kill(b->p, b, brigade_cleanup);
-    return apr_brigade_cleanup(b);
+#ifndef APR_BUCKET_DEBUG
+    return apr_pool_cleanup_run(b->p, b, brigade_cleanup);
+#else
+    apr_status_t rv;
+    
+    APR_BRIGADE_CHECK_CONSISTENCY(b);
+
+    rv = apr_pool_cleanup_run(b->p, b, brigade_cleanup);
+
+    /* Trigger consistency check failures if the brigade is
+     * re-used. */
+    b->p = NULL;
+    b->bucket_alloc = NULL;
+
+    return rv;
+#endif
 }
 
 APR_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,

Modified: apr/apr/trunk/include/apr_buckets.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_buckets.h?rev=951762&r1=951761&r2=951762&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_buckets.h (original)
+++ apr/apr/trunk/include/apr_buckets.h Sat Jun  5 20:43:15 2010
@@ -288,8 +288,11 @@ typedef apr_status_t (*apr_brigade_flush
  */
 #ifdef APR_BUCKET_DEBUG
 
-#define APR_BRIGADE_CHECK_CONSISTENCY(b)				\
-        APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
+#define APR_BRIGADE_CHECK_CONSISTENCY(b) do {                   \
+    APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link);   \
+    assert(b->p != NULL);                                       \
+    assert(b->bucket_alloc != NULL);                            \
+} while (0)
 
 #define APR_BUCKET_CHECK_CONSISTENCY(e)					\
         APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)