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.
Would this be a good time to mention that my book has a Chinese
translation?
--
Nick Kew
Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/