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 Weiming Yin <yi...@gmail.com> on 2009/02/23 04:25:15 UTC

Re: A question about cross request memory/pool usage

Hi, Nick

On Fri, Feb 20, 2009 at 3:42 PM, Nick Kew <ni...@webthing.com> wrote:

>
> On 20 Feb 2009, at 03:14, Weiming Yin wrote:
>
>  Hi
>>
>
> [answering here, but in future please post questions like this to the
> modules dev list]
>
>
>> I am writing an Apache module, I wanna setup some configure variable in
>> the module via a http request. The variable saved into a apr_hash_t in my
>> own module configure. But in the next request (the fixup handler), the one
>> with saved into the apr_hash_t is disappeared. I don't know why, is the
>> memory pool usage issue?
>>
>
> Most likely your requests are running in different processes, though you
> don't
> give enough information to be certain.
>
>  ...
>> var_t *var = apr_palloc(r->pool, sizeof(var_t));
>> apr_hash_set(cfg->var_hash, var->key, APR_HASH_KEY_STRING, var);
>>
>
> That's problematic for several reasons.   r->pool doesn't have the lifetime
> you want.
> The server pool does, but allocating from it in a request is a memory leak
> and not
> thread-safe.  Likewise setting cfg->hash there is not thread-safe.


I tested the r->server->process->pool, but I got a very strange result.
Sometimes (or some requests) it gives me some right result (the module
remember the variables into the hash), but sometimes it not. I donot know
why.


>
>
> Would this be a good time to mention that my book has a Chinese
> translation?


Your book, the new one? Which one, I got a Chinese translated <The Apache
Modules Book> on my hand.
I can find some friends to ask them if the have time and we can translate
the book into Chinese.


>
> --
> Nick Kew
>
> Application Development with Apache - the Apache Modules Book
> http://www.apachetutor.org/
>



-- 
Weiming Yin