httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thib <chep...@gmail.com>
Subject Re: How to manage memory allocation/free in the handler ?
Date Fri, 04 Apr 2008 13:27:59 GMT
Hi,

Thanks for this response.

For the new config, there is no problem because I create a new one only when
my "create config method" (create_snu_config method) is called :

static void *create_snu_config(apr_pool_t *p, server_rec *s)
{
   ...
   newcfg = (snu_config *) apr_pcalloc(p, sizeof(snu_config));
   ...
}

However, on the handler method (snu_handler) which is called at each time a
client perform a request, I need to allocate memory. I wrote the following
instruction :

static int snu_handler(request_rec *r)
{
   ...
   eni.calling = (char *) apr_pcalloc(r->pool, TAILL_CHAMPS * sizeof(char));
   ...
}

My mistake was "how to free this allocated memory?".

If I understand well:

   - The request_rec pool (r->pool) is not the same pool as the
   apr_pool_t "p" used in the create_snu_config method
   - The request_rec pool (r->pool) is free automatically at the end of
   the client request (end of the snu_handler pool)

Thanks a lot for your help (and sorry for my english).

Thib




2008/4/4, Eric Covener <covener@gmail.com>:
>
> On Fri, Apr 4, 2008 at 8:07 AM, Thib <cheprod@gmail.com> wrote:
>
> >  For example, in create_snu_config : new_cfg = (snu_config *)
> apr_pcalloc(p,
> >  sizeof(snu_config));
> >
> >  And I don't know how to free this memory at the end of the handler
> method. I
> >  don't find any method in apr to do that (as apr_pfree...).
> >
>
> Each pool available to you  at different stages has a fixed lifetime
> and is cleaned up by apache, including recliaming anything you've
> allocated.  You shouldn't have to manually manipulate this unless you
> want it to live shorter/longer then a pool you have access to.
>
> Are you creating a new config too often?  Normal data that only has to
> live as long as a request should be allocated out of r->pool ("request
> pool")
>
> http://www.apachetutor.org/dev/pools
>
> --
> Eric Covener
> covener@gmail.com
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message