Skip to content

Commit 5514c1a

Browse files
committed
Fix pool debugging. With lifetime or owner checks enabled, pools couldn't
even be created, except for the global pool which is a special case. * memory/unix/apr_pools.c (struct apr_pool_t): Add an 'unmanaged' member for pool-debug mode. The lifetime checks must be skipped for unmanaged pools, since they inevitably fail: apr_pool_is_child_of() expects all pools to have a parent, which obviously is not the case for unmanaged pools. (apr_pool_create_ex_debug): Create the pool's mutex after the parent has been assigned, because that involves an allocation which triggers a lifetime check which ... well, see above. (apr_pool_create_unmanaged): Set the pool->unmanaged flag and create the pool's mutex after the owner and allocator have been assigned. A pool without the owner set fails the ownershhip check, and without an allocator it's sort of hard to allocate space for the mutex. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1927658 13f79535-47bb-0310-9956-ffa450edef68
1 parent 34686fa commit 5514c1a

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

memory/unix/apr_pools.c

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ struct apr_pool_t {
600600
apr_os_thread_t owner;
601601
apr_thread_mutex_t *mutex;
602602
#endif /* APR_HAS_THREADS */
603+
int unmanaged;
603604
#endif /* APR_POOL_DEBUG */
604605
#ifdef NETWARE
605606
apr_os_proc_t owner_proc;
@@ -1619,7 +1620,8 @@ static void apr_pool_check_lifetime(apr_pool_t *pool)
16191620
* people have searched for the top level parent and
16201621
* started to use that...
16211622
*/
1622-
if (pool == global_pool || global_pool == NULL)
1623+
if (pool == global_pool || global_pool == NULL
1624+
|| (pool->parent == NULL && pool->unmanaged))
16231625
return;
16241626

16251627
/* Lifetime
@@ -2063,6 +2065,22 @@ APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
20632065
pool->owner_proc = (apr_os_proc_t)getnlmhandle();
20642066
#endif /* defined(NETWARE) */
20652067

2068+
if ((pool->parent = parent) != NULL) {
2069+
pool_lock(parent);
2070+
2071+
if ((pool->sibling = parent->child) != NULL)
2072+
pool->sibling->ref = &pool->sibling;
2073+
2074+
parent->child = pool;
2075+
pool->ref = &parent->child;
2076+
2077+
pool_unlock(parent);
2078+
}
2079+
else {
2080+
pool->sibling = NULL;
2081+
pool->ref = NULL;
2082+
}
2083+
20662084
#if APR_HAS_THREADS
20672085
if (parent == NULL || parent->allocator != allocator) {
20682086
apr_status_t rv;
@@ -2086,22 +2104,6 @@ APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
20862104
}
20872105
#endif /* APR_HAS_THREADS */
20882106

2089-
if ((pool->parent = parent) != NULL) {
2090-
pool_lock(parent);
2091-
2092-
if ((pool->sibling = parent->child) != NULL)
2093-
pool->sibling->ref = &pool->sibling;
2094-
2095-
parent->child = pool;
2096-
pool->ref = &parent->child;
2097-
2098-
pool_unlock(parent);
2099-
}
2100-
else {
2101-
pool->sibling = NULL;
2102-
pool->ref = NULL;
2103-
}
2104-
21052107
#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
21062108
apr_pool_log_event(pool, "CREATE", file_line, 1);
21072109
#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */
@@ -2130,10 +2132,29 @@ APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex_debug(apr_pool_t **newpoo
21302132

21312133
memset(pool, 0, SIZEOF_POOL_T);
21322134

2135+
pool->unmanaged = 1;
21332136
pool->abort_fn = abort_fn;
21342137
pool->tag = file_line;
21352138
pool->file_line = file_line;
21362139

2140+
#if APR_HAS_THREADS
2141+
pool->owner = apr_os_thread_current();
2142+
#endif /* APR_HAS_THREADS */
2143+
#ifdef NETWARE
2144+
pool->owner_proc = (apr_os_proc_t)getnlmhandle();
2145+
#endif /* defined(NETWARE) */
2146+
2147+
if ((pool_allocator = allocator) == NULL) {
2148+
apr_status_t rv;
2149+
if ((rv = apr_allocator_create(&pool_allocator)) != APR_SUCCESS) {
2150+
if (abort_fn)
2151+
abort_fn(rv);
2152+
return rv;
2153+
}
2154+
pool_allocator->owner = pool;
2155+
}
2156+
pool->allocator = pool_allocator;
2157+
21372158
#if APR_HAS_THREADS
21382159
{
21392160
apr_status_t rv;
@@ -2154,24 +2175,6 @@ APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex_debug(apr_pool_t **newpoo
21542175
}
21552176
#endif /* APR_HAS_THREADS */
21562177

2157-
#if APR_HAS_THREADS
2158-
pool->owner = apr_os_thread_current();
2159-
#endif /* APR_HAS_THREADS */
2160-
#ifdef NETWARE
2161-
pool->owner_proc = (apr_os_proc_t)getnlmhandle();
2162-
#endif /* defined(NETWARE) */
2163-
2164-
if ((pool_allocator = allocator) == NULL) {
2165-
apr_status_t rv;
2166-
if ((rv = apr_allocator_create(&pool_allocator)) != APR_SUCCESS) {
2167-
if (abort_fn)
2168-
abort_fn(rv);
2169-
return rv;
2170-
}
2171-
pool_allocator->owner = pool;
2172-
}
2173-
pool->allocator = pool_allocator;
2174-
21752178
#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
21762179
apr_pool_log_event(pool, "CREATEU", file_line, 1);
21772180
#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */

0 commit comments

Comments
 (0)