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.

Thank you,
Andrej


*** glibc detected *** /usr/local/httpd-2.2.15/bin/httpd: double free
or corruption (!prev): 0x09461298 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7d5d454]
/lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7d5f4b6]
/usr/local/httpd-2.2.15/lib/libapr-1.so.0(apr_allocator_destroy+0x2e)[0xb7f3d2ce]
/usr/local/httpd-2.2.15/lib/libapr-1.so.0(apr_pool_destroy+0x235)[0xb7f3dfa5]
/usr/local/httpd-2.2.15/bin/httpd[0x80aa4c4]
/usr/local/httpd-2.2.15/bin/httpd[0x80aa986]
/usr/local/httpd-2.2.15/bin/httpd[0x80aabe3]
/usr/local/httpd-2.2.15/bin/httpd(ap_mpm_run+0x5fa)[0x80ab26a]
/usr/local/httpd-2.2.15/bin/httpd(main+0xac8)[0x80696d8]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7d04685]
/usr/local/httpd-2.2.15/bin/httpd[0x8068601]
======= Memory map: ========
08048000-080c7000 r-xp 00000000 fe:00 1171716
/usr/local/httpd-2.2.15/bin/httpd
080c7000-080c8000 r--p 0007e000 fe:00 1171716
/usr/local/httpd-2.2.15/bin/httpd
080c8000-080cb000 rw-p 0007f000 fe:00 1171716
/usr/local/httpd-2.2.15/bin/httpd
080cb000-080ce000 rw-p 080cb000 00:00 0
09254000-09479000 rw-p 09254000 00:00 0          [heap]
b6465000-b6466000 ---p b6465000 00:00 0

Reply via email to