apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r758648 - /apr/apr/trunk/memory/unix/apr_pools.c
Date Thu, 26 Mar 2009 13:55:32 GMT
Author: jorton
Date: Thu Mar 26 13:55:26 2009
New Revision: 758648

URL: http://svn.apache.org/viewvc?rev=758648&view=rev
Log:
* memory/unix/apr_pools.c (struct apr_pool_t): Inline two block structures
  to avoid having to malloc them in apr_pool_create.
  (apr_pool_create): Switch the ->blocks pointer between the two
  block structures.  Avoid freeing either.
  (block_list_destroy_all): Don't free the final block_list_t.

Modified:
    apr/apr/trunk/memory/unix/apr_pools.c

Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=758648&r1=758647&r2=758648&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Thu Mar 26 13:55:26 2009
@@ -485,6 +485,8 @@
     apr_abortfunc_t       abort_fn;
     apr_hash_t           *user_data;
     const char           *tag;
+    block_list_t         first_block, final_block;
+    
     block_list_t        *blocks;
 
 #if APR_HAS_THREADS
@@ -512,7 +514,6 @@
     cleanup_t            *pre_cleanups;
     cleanup_t            *free_pre_cleanups;
     cleanup_t            *final_cleanups;
-    block_list_t         *final_blocks;
 };
 
 #define SIZEOF_POOL_T       APR_ALIGN_DEFAULT(sizeof(apr_pool_t))
@@ -676,7 +677,6 @@
     for (i = 0; i < ml->offset; i++) {
         free(ml->entries[i]);
     }
-    free(ml);
 }
 
 static void block_list_destroy_all(block_list_t *ml)
@@ -685,6 +685,9 @@
     for (i = ml; i != NULL; i = j) {
         j = i->next;
         block_list_destroy(i);
+        /* The last block is not malloc-allocated, so only free the
+         * block_list_t * for previous blocks. */
+        if (j) free(i);
     }
 }
 
@@ -783,7 +786,7 @@
 
     block_list_destroy_all(pool->blocks);
     run_cleanups(&pool->final_cleanups);
-    block_list_destroy_all(pool->final_blocks);
+    block_list_destroy(&pool->final_block);
     free(pool);
 }
 
@@ -816,14 +819,14 @@
     pool->subprocesses = NULL;
     pool->user_data = NULL;
     pool->tag = NULL;
-    pool->blocks = malloc(sizeof(block_list_t));
+
+    pool->blocks = &pool->final_block;
     pool->blocks->offset = 0;
     pool->blocks->next = NULL;
     (void)apr_thread_mutex_create(&pool->mutex,
                                   APR_THREAD_MUTEX_NESTED, pool);
-    pool->final_blocks = pool->blocks;
     pool->final_cleanups = pool->cleanups;
-    pool->blocks = malloc(sizeof(block_list_t));
+    pool->blocks = &pool->first_block;
     pool->blocks->offset = 0;
     pool->blocks->next = NULL;
     pool->cleanups = NULL;



Mime
View raw message