summaryrefslogtreecommitdiff
path: root/threadproc/netware/thread.c
diff options
context:
space:
mode:
authorylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-01-19 11:27:35 +0000
committerylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-01-19 11:27:35 +0000
commit04dcabc8d6ddc69a215fd8e60a5a60d5fcee4b3c (patch)
tree5a9aaee65ea66a401668f2169e88b15744ddd173 /threadproc/netware/thread.c
parent7f2e30e8a3960de2f84ec5766cabca12c24774fb (diff)
downloadlibapr-04dcabc8d6ddc69a215fd8e60a5a60d5fcee4b3c.tar.gz
apr_thread: Allocate the apr_thread_t struct on the thread's pool.
apr_thread_create() was allocating the created apr_thread_t on the given pool, which caused e.g. short-living threads to leak memory on that pool without a way to clear it (while some threads are still running). Change this by allocating the apr_thread_t on the thread's pool itself, which is safe in the implementations of all archs because none uses the apr_thread_t after the thread exits, and it's safe for the users provided they don't use the apr_thread_t for detached threads or for attached threads after the call to apr_thread_join(). These are hardly new requirements though. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1897197 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc/netware/thread.c')
-rw-r--r--threadproc/netware/thread.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 34a5691f5..a661ef886 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -87,12 +87,8 @@ apr_status_t apr_thread_create(apr_thread_t **new,
unsigned long flags = NX_THR_BIND_CONTEXT;
size_t stack_size = APR_DEFAULT_STACK_SIZE;
apr_allocator_t *allocator;
+ apr_pool_t *p;
- (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
- if ((*new) == NULL) {
- return APR_ENOMEM;
- }
-
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
@@ -103,29 +99,35 @@ apr_status_t apr_thread_create(apr_thread_t **new,
if (stat != APR_SUCCESS) {
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&(*new)->pool,
- apr_pool_abort_get(pool),
+ stat = apr_pool_create_unmanaged_ex(&p, apr_pool_abort_get(pool),
allocator);
if (stat != APR_SUCCESS) {
apr_allocator_destroy(allocator);
return stat;
}
- apr_allocator_owner_set(allocator, (*new)->pool);
+ apr_allocator_owner_set(allocator, p);
+
+ (*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
+ if ((*new) == NULL) {
+ apr_pool_destroy(p);
+ return APR_ENOMEM;
+ }
+ (*new)->pool = p;
(*new)->data = data;
(*new)->func = func;
(*new)->exitval = -1;
(*new)->detached = (attr && apr_threadattr_detach_get(attr) == APR_DETACH);
if (attr && attr->thread_name) {
- (*new)->thread_name = apr_pstrndup(pool, ttr->thread_name,
+ (*new)->thread_name = apr_pstrndup(p, ttr->thread_name,
NX_MAX_OBJECT_NAME_LEN);
}
else {
- (*new)->thread_name = apr_psprintf(pool, "APR_thread %04d",
+ (*new)->thread_name = apr_psprintf(p, "APR_thread %04d",
++thread_count);
}
if ((*new)->thread_name == NULL) {
- apr_pool_destroy((*new)->pool);
+ apr_pool_destroy(p);
return APR_ENOMEM;
}
@@ -160,7 +162,7 @@ apr_status_t apr_thread_create(apr_thread_t **new,
/* NXThreadId_t *thread_id */ &(*new)->td);
if (stat) {
- apr_pool_destroy((*new)->pool);
+ apr_pool_destroy(p);
return stat;
}