You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jw...@apache.org on 2001/06/19 04:57:20 UTC

cvs commit: apr-util/buckets apr_buckets_mmap.c

jwoolley    01/06/18 19:57:20

  Modified:    buckets  apr_buckets_mmap.c
  Log:
  Tweaks to mmap_setaside():
  
  *) Fix a memory leak: after calling apr_bucket_pool_make() to morph the
     bucket, you have to call mmap_destroy(); otherwise, you leak the
     apr_bucket_mmap struct after the last reference to it goes away.
  
  *) Use palloc() instead of pcalloc() to get the memory to copy into
     since we're about to overwrite it anyway.
  
  Revision  Changes    Path
  1.37      +7 -6      apr-util/buckets/apr_buckets_mmap.c
  
  Index: apr_buckets_mmap.c
  ===================================================================
  RCS file: /home/cvs/apr-util/buckets/apr_buckets_mmap.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -d -u -r1.36 -r1.37
  --- apr_buckets_mmap.c	2001/06/14 22:56:13	1.36
  +++ apr_buckets_mmap.c	2001/06/19 02:57:18	1.37
  @@ -117,25 +117,26 @@
   
   static apr_status_t mmap_setaside(apr_bucket *data, apr_pool_t *p)
   {
  -    apr_bucket_mmap *m;
  -    apr_mmap_t *mm;
  +    apr_bucket_mmap *m = data->data;
  +    apr_mmap_t *mm = m->mmap;
       char *base;
       void *addr;
       apr_status_t ok;
   
  -    m = data->data;
  -    mm = m->mmap;
       if (apr_pool_is_ancestor(mm->cntxt, p)) {
           return APR_SUCCESS;
       }
  -    
  -    base = apr_pcalloc(p, data->length);
  +
       ok = apr_mmap_offset(&addr, m->mmap, data->start);
       if (ok != APR_SUCCESS) {
           return ok;
       }
  +
  +    base = apr_palloc(p, data->length);
       memcpy(base, addr, data->length);
       data = apr_bucket_pool_make(data, base, data->length, p);
  +    mmap_destroy(m);
  +
       return APR_SUCCESS;
   }