httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ras...@lerdorf.on.ca
Subject Re: alloc.c etc.
Date Tue, 14 Jan 1997 05:50:44 GMT
>      I am confused about alloc.c -- I thought that memory allocated
> with malloc was subsequently free'd when destroy_sub_pool is called. I
> looked through the source, and couldn't find any calls to free() in
> alloc.c
>      How does this stuff work? I'm trying to track down a memory
> leak...

There is no need for any calls to free() in the Apache pool-based memory
allocation scheme.  malloc'ed memory cannot be returned to the system
until after the process exits anyway.  All free() does is indicate that the
memory block free'ed is available for re-use by the same process.  If you
look in alloc.c, you will find that the free_blocks() function is the one
that actually goes through a pool data structure and marks the blocks as being
available.

Since we have our own mechanism for re-using memory that is no longer needed,
the free() step is skipped completely.  When you destroy a sub-pool
you simply mark it as available for re-assignment when the next thing
comes along and asks for a new pool.  The only way something can leak is
if it gets into some sort of loop and keeps asking for more pools.
A second way something could leak is if it goes around the pool scheme and
does a malloc() on its own without free'ing the memory.  Perhaps a module
somewhere is calling strdup() or even malloc() directly in your code?

-Rasmus

Mime
View raw message