I think I have been seeing the same thing for a long time when refreshing entries
in mod_mem_cache. If you find something in the alloc path I will be
more than happy to try it in my lab.
"Jean-Jacques Clar" <JJCLAR@novell.com> on 05/21/2002 06:23:58 PM

To:    W G Stoddard/Raleigh/IBM@IBMUS
Subject:    memory leak


I still have a memory leak when refreshing expired entries  in the
On heavy load - short expire interval it gets pretty ugly (1  Mb every 4

It looks like some allocators are never being  freed.
Here are the calls leading to a leak:
    there is a pre-existing cache handle and  new entity, replacing it
  cache_write_entity_body() ->  write_body()

when it calls apr_bucket_read()
(then  file_bucket_read()->apr_bucket_alloc()->apr_allocator_alloc() and
finally  malloc())
in the following loop from write_body():
In apr_allocator_alloc, it looks like once  in a while there are no free
( allocator->max_index = 0), so calls to malloc are made.
However, the previously allocated memory in the allocator does  not look to
be freed.
This is how the leak is happening.

    /* Iterate across the brigade and populate the cache  storage */
        const char  *s;
        apr_size_t len;

        if (APR_BUCKET_IS_EOS(e))
            /* Open  for business  */
             obj->complete =  1;

        rv = apr_bucket_read(e, &s,  &len, eblock);
        if (rv !=  APR_SUCCESS)
            return  rv;

        if (len)
            /* Check  for buffer overflow  */
           if  ((obj->count + len) > mobj->m_len)
                return  APR_ENOMEM;

                memcpy(cur, s,  len);

        /* This should not happen, but  if it does, we are in BIG  trouble
         * cause we just  stomped all over the heap.
        AP_DEBUG_ASSERT(obj->count  > mobj->m_len);
Do you have any suggestions on what I should try to find a  solution to
that leak?

Let me known if you need more details.
Thank you very much,

Jean-Jacques Clar

>>> striker@apache.org 09/09/02 03:11PM >>>
> From: Cliff Woolley [mailto:jwoolley@virginia.edu]
> Sent: 09 September 2002 22:42

> On Mon, 9 Sep 2002, Brad Nicholes wrote:
> >      Has anybody else noticed a memory leak when requesting pages less
> > than 8k?  If I repeatedly request pages less than 8k I have noticed that
> > apr_bucket_alloc() calls allocator_alloc() which seems to continuously
> > malloc() memory rather than finding it in the free list.  The reason why
> > is because allocator->max_index seems to always be 0 and contain no free
> > nodes.  If I request pages greater than 8k, allocator->max_index appears
> > to be 2.  I can't seem to figure out why the bucket allocator passed in
> > by apr_bucket_alloc always contains a max_index of 0 on small page
> > requests.  Any ideas?
> Ughuuhhhhhh ... good question!  I'll let Sander take a stab at that one
> before I try to dig in and see what's going on... but I will do so if no
> answers are forthcoming in the near-term.

I'll give it a look tomorrow.  I've got a pretty decent hunch on what is
going on...