Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 17669 invoked by uid 500); 30 Jun 2003 19:11:02 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 17650 invoked from network); 30 Jun 2003 19:11:01 -0000 Message-ID: <3EFFA95F.7010300@cultura.com.br> Date: Mon, 30 Jun 2003 00:07:11 -0300 From: ranier User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030507 X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@apr.apache.org Subject: [PATH] debug ideas for memory allocation Content-Type: multipart/mixed; boundary="------------090603070808010804000804" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------090603070808010804000804 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi, I read a Steve Maguire book named "Guia Microsoft para o desenvolvimento de programas sem erros" [ironic not?] and add some ideas for debugging memory allocation in apr_pool.c. 1. Memory not initialized or freed is trash, on debug force this! 2. Use intensive of the function "assert" on debug development. I wait to be helping. Thanks in advace. Ranier Vilela RC Software --------------090603070808010804000804 Content-Type: text/plain; name="apr_pools.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="apr_pools.diff" --- apr_pools-old.c 2003-06-29 22:51:25.000000000 -0300 +++ apr_pools.c 2003-06-29 23:49:16.000000000 -0300 @@ -52,6 +52,7 @@ * . */ +#include "assert.h" #include "apr.h" #include "apr_private.h" @@ -1339,6 +1340,12 @@ pool->stat_alloc++; pool->stat_total_alloc++; + + /* + * Memory not initialized is trash! Force this! + */ + memset(mem, APR_MEMORY_TRASH, size); + return mem; } @@ -1347,6 +1354,8 @@ { void *mem; + assert( pool != NULL && size > 0 ); + apr_pool_check_integrity(pool); mem = pool_alloc(pool, size); @@ -1363,6 +1372,8 @@ { void *mem; + assert( pool != NULL && size > 0 ); + apr_pool_check_integrity(pool); mem = pool_alloc(pool, size); @@ -1385,6 +1396,8 @@ debug_node_t *node; apr_uint32_t index; + assert( pool != NULL ); + /* Destroy the subpools. The subpools will detach themselves from * this pool thus this loop is safe and easy. */ @@ -1406,9 +1419,15 @@ while ((node = pool->nodes) != NULL) { pool->nodes = node->next; - for (index = 0; index < node->index; index++) + for (index = 0; index < node->index; index++) { + /* Memory freed is trash! Force this! */ + memset( node->beginp[index], APR_MEMORY_TRASH, (node->endp[index] - node->beginp[index]) ); + free(node->beginp[index]); + } + /* Memory freed is trash! Force this! */ + memset( node, APR_MEMORY_TRASH, SIZEOF_DEBUG_NODE_T ); free(node); } @@ -1423,6 +1442,8 @@ apr_thread_mutex_t *mutex = NULL; #endif + assert( pool != NULL ); + apr_pool_check_integrity(pool); #if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) @@ -1462,6 +1483,8 @@ APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool, const char *file_line) { + assert( pool != NULL ); + apr_pool_check_integrity(pool); #if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) @@ -1493,6 +1516,9 @@ apr_allocator_destroy(pool->allocator); } + /* Memory freed is trash! Force this! */ + memset(pool, APR_MEMORY_TRASH, SIZEOF_POOL_T); + /* Free the pool itself */ free(pool); } @@ -1573,7 +1599,11 @@ */ if ((rv = apr_thread_mutex_create(&pool->mutex, APR_THREAD_MUTEX_NESTED, pool)) != APR_SUCCESS) { + + /* Memory freed is trash! Force This! */ + memset( pool, APR_MEMORY_TRASH, SIZEOF_POOL_T ); free(pool); + return rv; } #endif /* APR_HAS_THREADS */ --------------090603070808010804000804--