You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Sorin Manolache <so...@gmail.com> on 2010/04/22 09:22:48 UTC

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

On Thu, Apr 22, 2010 at 05:47, Andrej van der Zee
<an...@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

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by bronto <br...@noip.sk>.
On 4/22/2010 1:46 PM, Andrej van der Zee wrote:
> Hi Bronto,
>
>    
>> http://lmgtfy.com/?q=apache+httpd+valgrind
>>
>>      
> Thank you for the tip :) You are funny!
>
> Cheers,
> Andrej
>    
Hi,

yeah, i didn't mean no offense. I just thought that it's rather a FAQ ;)

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by Andrej van der Zee <an...@gmail.com>.
Hi Bronto,

>
> http://lmgtfy.com/?q=apache+httpd+valgrind
>

Thank you for the tip :) You are funny!

Cheers,
Andrej

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by bronto <br...@noip.sk>.
On 4/22/2010 1:09 PM, Andrej van der Zee wrote:
> Hi,
>
>
>    
>> This and try running httpd through valgrind.
>>
>>      
> How can I do that?
>
> Thanks,
> Andrej
>    

http://lmgtfy.com/?q=apache+httpd+valgrind

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by Andrej van der Zee <an...@gmail.com>.
Hi,


>
> This and try running httpd through valgrind.
>

How can I do that?

Thanks,
Andrej

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
> 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.

This and try running httpd through valgrind.

Re: *** glibc detected *** double free or corruption (!prev) in cleanup function

Posted by Andrej van der Zee <an...@gmail.com>.
Hi,

> 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?

The background thread is created by ap_hook_child_init, thus every
child process has one running 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.

Even when I do not join at all, but just attempt to connect to the
database in the registered pool cleanup function for the child, I get
the segfault.

>
> 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.

Yes I'll try that soon.

Thank you,
Andrej