httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Stoddard <b...@wstoddard.com>
Subject Re: Potential memory leak in /modules/cache/mod_mem_cache.c
Date Fri, 04 Nov 2005 13:23:33 GMT
Xuekun Hu wrote:
> So, same reason. Also in file mod_mem_cache.c around line 786, there
> is a malloc(mobj->m_len), and a few lines later, another
> malloc(obj->count) is performed.
> 
> If the second malloc fails, I think also should add something like
>   free(mobj->m);
>   mobj->m = NULL;
> 
> reasonable?

No.  Once a cache object is allocated, it will be cleaned up by cleanup_cache_object when
the reference count 
drops to 0. To understand how this works, find this line of code.

    apr_pool_cleanup_register(r->pool, obj, decrement_refcount,
                               apr_pool_cleanup_null);

When r->pool is cleaned up, decrement_refcount is called. decrement_refcount will call
cleanup_cache_onject 
when the refcount goes to 0.

Bill


Mime
View raw message