Currently in apr_pool_destroy there is this chunk of code while (pool->child) apr_pool_destroy(pool->child);
run_cleanups(&pool->cleanups); The problem here is if I created a subpool for temporary scratch space, then registered that subpool as a cleanup the pool will be cleaned up in the first chunk of code. while (pool->child) apr_pool_destroy(pool->child); THEN will be run again with run_cleanups(&pool->cleanups); causing a segmentation fault. This code here Fixed the problem by running the cleanups first then destroying the subpools. run_cleanups(&pool->cleanups); while (pool->child) apr_pool_destroy(pool->child); Sample pseudo//simplified code that causes the problem is below for further clarification. apr_status_t file_field_clean( t ) { apr_pool_destroy( t->read_pool ); apr_pool_destroy( t->write_pool ); free(t); return APR_SUCCESS; } struct ffm_t file_field_init( apr_pool_t * pool ) { struct ffm_t * t; t = malloc( sizeof( struct ffm_t ) ); if ( apr_pool_create( &(t->read_pool), pool ) != APR_SUCCESS ) { return NULL; } if ( apr_pool_create( &(t->write_pool), pool ) != APR_SUCCESS ) { return NULL; } apr_pool_cleanup_register( pool, t, file_field_clean, file_field_clean ); return t; }