On Thu, Apr 22, 2010 at 05:47, Andrej van der Zee <andrejvander...@gmail.com> wrote: > Hi, > > I have a question about apr_pool_cleanup_register for a child's pool. > I register a cleanup function that is called when the pool is > destroyed. In the cleanup function, I join a background thread that > first writes some log to a database: > > static void mbrace_child_init(apr_pool_t *pool, server_rec *s) > { > apr_pool_cleanup_register(pool, 0, &mbrace_bgthread_cleanup, > apr_pool_cleanup_null); > } > > static apr_status_t mbrace_bgthread_cleanup(void*) > { > req_log_mngr->stop() > } > > But, when it connects to the database in the background thread, it > sometimes ends up in the error below. I do not fully understand why, > but are there any restrictions to what I can do in the cleanup > function? > > When running gdb on the generated core-dump, you can see that it > happens on line 134. > > 125 APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator) > 126 { > 127 apr_uint32_t index; > 128 apr_memnode_t *node, **ref; > 129 > 130 for (index = 0; index < MAX_INDEX; index++) { > 131 ref = &allocator->free[index]; > 132 while ((node = *ref) != NULL) { > 133 *ref = node->next; > 134 free(node); <================ here it happens!! > 135 } > 136 } > 137 > 138 free(allocator); > 139 } > > Hopefully somebody can push me in the right direction.
Do you create a background thread per apache process? Or do you have a single background thread that is used by all apache processes? Which hook creates the background thread? It is possible that you create the thread once but you try to join it several times. I don't know if this is sufficient to get the symptoms that you see. Try compiling both apache and apr with debug symbols and run it in a debugger with -X (i.e. monoprocess). Place a breakpoint on line 134 and see how many times you reach it. S