apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: apr-util/misc apr_reslist.c
Date Sun, 26 Sep 2004 14:36:27 GMT
mturk       2004/09/26 07:36:27

  Modified:    misc     apr_reslist.c
  Log:
  Fix memory leak when maintaining resources. When extra resources are
  destroyed they are returned to the free list, but they were never reused and
  the resource container has been created again. The patch makes sure that we
  create resource containers up to the hmax.
  
  Revision  Changes    Path
  1.10      +9 -8      apr-util/misc/apr_reslist.c
  
  Index: apr_reslist.c
  ===================================================================
  RCS file: /home/cvs/apr-util/misc/apr_reslist.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apr_reslist.c	15 Mar 2004 08:21:26 -0000	1.9
  +++ apr_reslist.c	26 Sep 2004 14:36:27 -0000	1.10
  @@ -85,17 +85,18 @@
   }
   
   /**
  - * Get an empty resource container from the free list.
  + * Get an resource container from the free list or create a new one.
    */
   static apr_res_t *get_container(apr_reslist_t *reslist)
   {
       apr_res_t *res;
   
  -    assert(!APR_RING_EMPTY(&reslist->free_list, apr_res_t, link));
  -
  -    res = APR_RING_FIRST(&reslist->free_list);
  -    APR_RING_REMOVE(res, link);
  -
  +    if (!APR_RING_EMPTY(&reslist->free_list, apr_res_t, link)) {
  +        res = APR_RING_FIRST(&reslist->free_list);
  +        APR_RING_REMOVE(res, link);
  +    }
  +    else
  +        res = apr_pcalloc(reslist->pool, sizeof(*res));
       return res;
   }
   
  @@ -116,7 +117,7 @@
       apr_status_t rv;
       apr_res_t *res;
   
  -    res = apr_pcalloc(reslist->pool, sizeof(*res));
  +    res = get_container(reslist);
   
       rv = reslist->constructor(&res->opaque, reslist->params, reslist->pool);
   
  @@ -215,11 +216,11 @@
           res = pop_resource(reslist);
           reslist->ntotal--;
           rv = destroy_resource(reslist, res);
  +        free_container(reslist, res);
           if (rv != APR_SUCCESS) {
               apr_thread_mutex_unlock(reslist->listlock);
               return rv;
           }
  -        free_container(reslist, res);
       }
   
       apr_thread_mutex_unlock(reslist->listlock);
  
  
  

Mime
View raw message