svn commit: r1935301 - apr/apr/trunk/memory/unix
[email protected] Sun, 14 Jun 2026 15:06:34 -0000
| Newsgroups | gmane.comp.apache.apr.cvs |
|---|---|
| Message-ID | <178144959424.1772569.13999055583942930333@svn03-he-fi> |
Author: brane
Date: Sun Jun 14 15:06:33 2026
New Revision: 1935301
Log:
Register unmanaged pools with Valgrind, otherwise it complains at every
allocation that the memory pool address is invalid.
Also consolidate the copy-pasted code for creating unmanaged and managed pools.
Modified:
apr/apr/trunk/memory/unix/apr_pools.c
Modified: apr/apr/trunk/memory/unix/apr_pools.c
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c Sun Jun 14 14:09:54 2026 (r1935300)
+++ apr/apr/trunk/memory/unix/apr_pools.c Sun Jun 14 15:06:33 2026 (r1935301)
@@ -1049,34 +1049,47 @@ APR_DECLARE(void) apr_pool_destroy(apr_p
APR_IF_VALGRIND(VALGRIND_DESTROY_MEMPOOL(pool));
}
-APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
- apr_pool_t *parent,
- apr_abortfunc_t abort_fn,
- apr_allocator_t *allocator)
+
+/* Create a managed or unmanaged pool. If PARENT is NULL, create an unmanaged
+ pool without a parent, otherwise create a managed pool under PARENT. */
+static apr_status_t create_pool(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator)
{
+ const int need_allocator = (allocator == NULL);
apr_pool_t *pool;
apr_memnode_t *node;
- *newpool = NULL;
-
- if (!parent)
- parent = global_pool;
+ if (!parent) {
+ /* We're creating an unmanaged pool. */
+ if (need_allocator) {
+ if (apr_allocator_create(&allocator) != APR_SUCCESS) {
+ if (abort_fn)
+ abort_fn(APR_ENOMEM);
- /* parent will always be non-NULL here except the first time a
- * pool is created, in which case allocator is guaranteed to be
- * non-NULL. */
-
- if (!abort_fn && parent)
- abort_fn = parent->abort_fn;
+ return APR_ENOMEM;
+ }
+ }
+ }
+ else {
+ if (!abort_fn)
+ abort_fn = parent->abort_fn;
- if (allocator == NULL)
- allocator = parent->allocator;
+ if (need_allocator)
+ allocator = parent->allocator;
+ }
if ((node = allocator_alloc(allocator,
MIN_ALLOC - APR_MEMNODE_T_SIZE)) == NULL) {
if (abort_fn)
abort_fn(APR_ENOMEM);
+ if (need_allocator && allocator != NULL) {
+ /* We created a new allocator but can't allocate, so destroy it. */
+ apr_allocator_destroy(allocator);
+ }
+
return APR_ENOMEM;
}
@@ -1135,70 +1148,44 @@ APR_DECLARE(apr_status_t) apr_pool_creat
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex(apr_pool_t **newpool,
- apr_abortfunc_t abort_fn,
- apr_allocator_t *allocator)
+APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator)
{
- apr_pool_t *pool;
- apr_memnode_t *node;
- apr_allocator_t *pool_allocator;
-
*newpool = NULL;
- if (!apr_pools_initialized)
- return APR_ENOPOOL;
- if ((pool_allocator = allocator) == NULL) {
- if (apr_allocator_create(&pool_allocator) != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(APR_ENOMEM);
-
- return APR_ENOMEM;
- }
- if ((node = allocator_alloc(pool_allocator,
- MIN_ALLOC - APR_MEMNODE_T_SIZE)) == NULL) {
- if (abort_fn)
- abort_fn(APR_ENOMEM);
+ if (!parent)
+ parent = global_pool;
- apr_allocator_destroy(pool_allocator);
+ /* parent will always be non-NULL here except the first time a
+ * pool is created, in which case allocator is guaranteed to be
+ * non-NULL. */
- return APR_ENOMEM;
- }
- }
- else if ((node = allocator_alloc(pool_allocator,
- MIN_ALLOC - APR_MEMNODE_T_SIZE)) == NULL) {
+ if (parent == NULL && allocator == NULL) {
if (abort_fn)
- abort_fn(APR_ENOMEM);
+ abort_fn(APR_ENOPOOL);
- return APR_ENOMEM;
+ return APR_ENOPOOL;
}
- node->next = node;
- node->ref = &node->next;
-
- pool = (apr_pool_t *)node->first_avail;
- node->first_avail = pool->self_first_avail = (char *)pool + SIZEOF_POOL_T;
+ return create_pool(newpool, parent, abort_fn, allocator);
+}
- pool->allocator = pool_allocator;
- pool->active = pool->self = node;
- pool->abort_fn = abort_fn;
- pool->child = NULL;
- pool->cleanups = NULL;
- pool->free_cleanups = NULL;
- pool->pre_cleanups = NULL;
- pool->subprocesses = NULL;
- pool->user_data = NULL;
- pool->tag = NULL;
- pool->parent = NULL;
- pool->sibling = NULL;
- pool->ref = NULL;
+APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex(apr_pool_t **newpool,
+ apr_abortfunc_t abort_fn,
+ apr_allocator_t *allocator)
+{
+ *newpool = NULL;
- if (!allocator)
- pool_allocator->owner = pool;
+ if (!apr_pools_initialized) {
+ if (abort_fn)
+ abort_fn(APR_ENOPOOL);
- pool_concurrency_init(pool);
- *newpool = pool;
+ return APR_ENOPOOL;
+ }
- return APR_SUCCESS;
+ return create_pool(newpool, NULL, abort_fn, allocator);
}
/*